CAn u provide us with ur test cases and corresponding answers pls…
since I am getting wrong answer .
#include
using namespace std;
int main()
{
int t,i,j,x,k;
int a[100][100];
int n[10];
x=0;
cin>>t;
for(i=0;i<t;i++)
{
cin>>n[i];
for(j=0;j<n[i];j++)
{
cin>>a[i][j];
}
}
for(k=0;k<t;k++)
{
for(i=0;i<n[k]-1;i++)
{
x=0;
for(j=i;j<n[k];j++)
{
if(((a[k][j]<0)&&(a[k][j+1]>0))||((a[k][j]>0)&&(a[k][j+1]<0)))
{
x=x+1;
}
else
{
break;
}
}
if(x==0)
{
cout<<"1";
}
else
{
cout<<x+1;
}
}
cout<<"1";
cout<<"\n";
}
return 0;
}
3
4
1 2 3 4
4
-1 2 -3 4
6
-2 -2 -3 5 -2 -1
My Approach:
Everytime you find a subarray whose longest alternating count is greater than one, all you have to do is print it, and decrement and print it till it becomes one. Then skip the next count-1 elements.
can tester tell me ur test cases and corresponding answers pls
In the dp solution why do you write a[i]*1ll*[i+1]
instead of simple a[i]*a[i+1]
,
I wrote the latter during contest and got wrong answer and when I changed it to former it was accepted later. I thought maybe it is to prevent int overflow but I tried making array as array of long long ints but still I got wrong answer.
https://www.codechef.com/viewsolution/9712232
This is link of my solution… getting wrong answer continuously…Still i cant found any bugg… Pls help me out
Did exactly the same way which is mentioned in Quick Explanation.
My Solution : CodeChef: Practical coding for everyone
#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…
Why u people dont tell ur testing test cases so that every one check why they are getting wrong answers…
Your solution fails for the following case:
1
2
1 1
The correct output is “1 1” whereas your program prints “2 1”.
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
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.