ALTARAY - Editorial

Why u people dont tell ur testing test cases so that every one check why they are getting wrong answers…

Why u people dont tell ur testing test cases so that every one check why they are getting wrong answers…

ok.i will take care of this now.
Apart frm that d program is ok na?

and thanks for helping

Please edit your answer to make it readable or provide the link to your solution.

@vineet1003

Your solution fails for the following case:

1

2

1 1

The correct output is “1 1” whereas your program prints “2 1”.

Please help>>

https://www.codechef.com/viewsolution/9723926

https://www.codechef.com/viewsolution/9723901

Can someone help me with my program. I am getting Time Limit Exceeded error
https://www.codechef.com/viewsolution/9739516

My program shows exactly the same output as shown in the problem but it still says “wrong answer”
please help me where i am going wrong?
here’s the link to my code
https://www.codechef.com/viewsolution/9755162

nice editorial

Can’t spot mistake…getting WA :’(

https://www.codechef.com/viewsolution/9757999

public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
int n;
while(t>0)
{
n=sc.nextInt();
long[] a=new long[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextLong();
}
int[] b=new int[n];
b[n-1]=1;
for(int i=n-2;i>=0;i–)
{

if(a[i]*a[i+1]<0)
b[i]=b[i+1]+1;
else
b[i]=1;
}
for(int x : b)
System.out.printf("%d ",x);
System.out.println();
t–;
}
}
}

time limit is exceeding

plz help

https://www.codechef.com/viewsolution/9972627
this is my solution.it works fine with the test cases but its not getting accepted. pls help
thanks in advance.

I would like to thank you for the time you invest in making such nice post cause as I think it can be very helpful for many people who just wish to get as much information about this topic as possible.

when i am running this code it is showing correct output, but when i am submitting it, it is showing wrong answer. Here is the link to my solution:
https://www.codechef.com/viewsolution/10155565

#include <stdio.h>

int a[100002];

int sign(int);

int dp(long long int, long long int,long long int);

int main(void) {
long long int n,t,i,x;
scanf("%lld",&t);
while(t–)
{
scanf("%lld",&n);
for(i=0;i<n;i++)
scanf("%lld",&a[i]);

      for(i=0;i<n;i++)
          {
            x=dp(i,sign(a[i]),n);
            printf("%lld ",x);
          }
       printf("\n");
        
    }
// your code goes here
return 0;

}

int dp(long long int y,long long int s,long long int n)
{
if(y==n-1)
return 1;

    else if(sign(a[y+1])!=s)
     return  1+dp(y+1,sign(a[y+1]),n);

    else
     return 1;

}

int sign(int n)
{
if(n>0)
return 1;

  else
   return 0;

}

why i am gtting tle while submitting .
running well for given test cases

I am getting time limit exceeding but cant see my mistake , plz help

import java.io.*;

import java.math.*;

import java.util.*;

class subarrayprefix
{

public static Long[] a=new Long[1000000];

public static Long[] ans=new Long[1000000];
public static void main(String arg[])
{
	Scanner sc=new Scanner(System.in);
	int t=sc.nextInt();
	int n;
	long x=1;
	while(t>0)
	{
		n=sc.nextInt();
		for(int i=0;i<n;i++)
			a[i]=sc.nextLong();
		ans[n-1]=x;
		for(int i=n-2;i>=0;i--)
		{
			if((a[i+1]*a[i])<0)
				ans[i]=ans[i+1]+1;
			else
				ans[i]=x;
		}
		for(int i=0;i<n;i++)
			System.out.printf("%d ",ans[i]);
		System.out.println();
		t--;
	}
}

}

https://www.codechef.com/viewsolution/10533083
Can you check why am I getting a WA ?

This problem can be easily solved using stacks. Here is my solution http://ideone.com/fork/WaJVs5 .
If you find anything incorrect please let me know.