ALTARAY - Editorial

Did exactly the same way which is mentioned in Quick Explanation.

My Solution : CodeChef: Practical coding for everyone

is my program correct?
someone pl tell
https://www.codechef.com/viewsolution/9714935

#include<stdio.h>
int main ()
{
int T=0,i=0,n=0,flag=0,c=0;
long long int j=0,count=0,A[100001];
scanf("%d",&T);
for(i=0;i<T;i++)
{
scanf("%d",&n);
for(j=1;j<=n;j++)
{
scanf("%lld",&A[j]);
}
for(j=1;j<=n;j++)
{
count=1;
flag=0;
c=j;
if(j==n)
{
printf("%d",1);
}
if(j!=n)
{
if(A[j]*A[j+1]>0&&j!=n)
{
printf("%d",1);
printf(" “);
}
else
{
while(A[j]*A[j+1]<0)
{
count++;
j++;
flag=1;
}
if(flag==1)
{
printf(”%lld",count);
printf(" ");
}
}
j=c;

        }
        }
        printf("\n");
    }
return(0);

}

can you please check where i got wrong?

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

1 Like

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

@vineet1003

Your solution fails for the following case:

1

2

1 1

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

1 Like

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 :cry:

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;

}

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 Online Compiler and IDE >> C/C++, Java, PHP, Python, Perl and 70+ other compilers and interpreters - Ideone.com .
If you find anything incorrect please let me know.

#include
#include <stdio.h>
#include

int main() {

int cases, i;
scanf("%d", &cases);
for (i=0; i<cases; i++) {
	int n,j,k;
	long int a[100000];
	scanf("%d", &n);
	for (j=0; j<n; j++)
		std::cin>>a[j];
	for (j=0; j<n; j++) {
		int count=1;
		for (k=j; k<n; k++) {
		    //printf("%d and %d\n", a[k], a[k+1]);
			if (a[k]*a[k+1] < 0)
				count++;
			else
			    break;
		}
		printf("%d ", count);		
	}
	printf("\n");
}

return 0;

}

What is wrong in this code, Why is it showing Wrong Answer !