What is wrong in my code , (CLOSCHEF)

#include <bits/stdc++.h>
#define ll long long int
using namespace std;

void solve(){
ll n,ans=1,t,c=0,d=0,e=0;
cin>>n;
for(int i=0; i<n; i++){
cin>>t;
if (t>1 || t<-1){c++;}
if(t==-1){d++;}
if(t==1){e++;}
if (c==2 || (d>0 && c>0)){ans=0; break;}
}
if(d>1 && e==0){ans=0;}
cout<<ans<<endl;
}

int main() {
ll t;
cin>>t;
while(t–){solve();}
return 0;
}

What does the variable a in ‘cout<<a<<endl;’ have? I don’t see anything assigned to it at all.

1 Like

thankyou for your reply , I mistakenly write a instead of ‘ans’ ,
but it is still showing WA while the test cases are running.

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

… link of my code.

Remove the break statement and It should work, since It won’t print the answer before having read all the numbers in input.

1 Like

you are using “break” in for loop. So, if that breaking condition satisfies then its execution starts from the outside loop. BUT you are taking input elements inside this loop i.e. cin>>t; This should not happen.

1 Like

Thankyou so much
I got it now.

I want one more suggestion … shall I delete my post now because it is a silly mistake.

Thankyou so much :smiley:
I got it now.

I want one more suggestion … shall I delete my post now because it is a silly mistake.

I think you should leave It for others facing the same issue in other problems, It Is not stupid if you are not used to It.

1 Like