I tried the editorial logic also. But still I am getting WA. Any suggestions will be really helpful.
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t!=0)
{
t–;
int n;
cin>>n;
string s;
cin>>s;
int g1=0;
int g2=0;
int sl1=n;
int sl2=n;
for(int i=0;i<s.length();i+=2)
{
if(s[i]==‘1’)
{
g1++;
sl1–;
}
else
{
sl1–;
}
//check function
//ends
if(s[i+1]=='1')
{
g2++;
sl2--;
}
else
{
sl2--;
}
//check function
if(g1>sl2+g2)
{
cout<<i+2;
goto hell;
}
else if(g2>sl1+g1)
{
cout<<i+2;
goto hell;
}
else
{
continue;
}
//ends
}
cout<<2*n;
hell:cout<<endl;
}
return 0;
}
Please post a link to your code or format it by placing the code part inside ``` and ```
It’s automatically giving strange identations. Wait I will post the link also.
Try this test case
3
000101
Your code gives the answer as 6 but it should be 5
1 Like
Yeah I made that one work. But still nothing. Maybe something is wrong with the approach.
What I am doing in my code is-
1)incrementing goals of both the teams and decreasing their shots left after going through two characters in the string at one time.
2)then checking if goals1 > (shotsleft2+goals2) or vice versa. If yes,the I print index+1 or index+2 depending on which team is leading.
3)If the above condition never fulfills I print 2*N at the end for a draw.
The code after updating - CodeChef: Practical coding for everyone
Try this case
2
1010
The answer should be 3 but your code gives 4
1 Like
Thank you bro. It worked .I wasn’t checking at proper intervals. 