ARRGAME - Editorial

How?
It will print " no".

Nice Editorial.
If possible provide the editorials of the rest of the questions

Same here

my 1st test case of second subtask is failing .can someone help?

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

can anyone suggest me for which test cases the answer is wrong.

To the people getting WA in subtask 2:
Let length of longest segment of zero be x;
1). if the x is even then the answer is No
2). if the x odd then:
if length of second longest segment of zero is greater than or equal to (x+1)/2 answer is No.
Explanation- let x be 5 and length of second longest segment of zero be 3 (eg - 110000010001) , in first move Nayeon land on middle element of segment of length 5 and tzuyu lands on segment of length 3 then after playing optimally tzuyu will win .If Nayeon lands on first elemnent of x in first move then tzuyu land on second element of x hence tzuyu wins. And similalrly in all other cases Tzuyu will win.

else answer is Yes.

1 Like

https://www.codechef.com/viewsolution/37262601
Can anyone tell me what am I doing wrong?

Nice problem
And nicely explanned

are the editorials of the other problems uploaded?

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

What the hell is wrong with my solution ?
I did the same what is mentioned in the editorial

Yeah got my mistake and corrected it but it is still fail for the 1st case of subtask 2 :frowning:

This is my corrected code but still not accepted . And actually i m using the same logic as mention in the editorial but can’t figure out the mistake . Can you plz help me with any other case or any wrong logic i m using .

https://www.codechef.com/viewsolution/37300016
Hi, I just made some changes to your code and it gets AC. The answer will be “yes” only when we have an odd segment. If there is only one segment and that is odd length, then the answer is ‘yes’. If there is more than one segment, then the 1st player chooses the longest odd segment, and then 2nd player chooses the largest vacant segment(odd or even does not matter). Now we just see if the length of segment chosen by 2nd is greater than or equal to (length of segment chosen by first + 1)/2.

1 Like

Can anyone please tell what I am missing?
https://www.codechef.com/viewsolution/37300895

Great man, Thanks for your support​:+1::+1:

Finally solved it…, CodeChef: Practical coding for everyone
#include <bits/stdc++.h>
using namespace std;

void solve(){
    int n;
    cin >> n;
    vector<int> v(n);
    map<int, int> mp;
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(v[i] == 0){
            cnt++;
        }else{
            if(cnt != 0)
                mp[cnt]++;
            cnt = 0;
        }
    }
    int mx_even = 0;
    int mx_odd = 0;
    for(auto it : mp){
        if(it.first &1)
            mx_odd = max(mx_odd, it.first);
        else{
            mx_even = max(mx_even, it.first);
        }
    }
    // find the second largest odd length zero-interval;
    int mx_odd2 = 0;
    for(auto it: mp){
        if(it.first &1 && it.first < mx_odd){
            mx_odd2 = max(mx_odd2, it.first);
        }
    }
    if(mx_odd){
        if(mx_odd == 1){
            if(mp[mx_odd] > 1 || mx_even > mx_odd){
                cout << "No\n";
            }else{
                cout << "Yes\n";
            }
        }
        else{
            if(mp[mx_odd] > 1 || (mx_odd && mx_odd2 > mx_odd/2) || mx_even >mx_odd/2){
                cout << "No\n";
            }
            else{
                cout << "Yes\n";
            }
        }
    }else{
        cout << "No\n";
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int tt;
    cin >> tt;
    while(tt--){
        solve();
    }
    return 0;
}


indent preformatted text by 4 spaces

I learnt from previous contests,was stuck for an hour in a previous contest.Yeah and in codeforces it doesnt matter i think ,if you are printing YES or Yes

Why WA?

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
int t;
cin>>t;
while(t--)
{
long int n,max1=0,max2=0,cnt=0;
cin>>n;
int x;

f(i,n)
{
    cin>>x;
    if(x)
    {
     if(max1<=cnt)
     {
         max2=max1;
         max1=cnt;
         cnt=0;
         continue;
     }
        if(max2<=cnt)
     {
         max2=cnt;
         cnt=0;
         continue;
     }
    }
     else
     {
      if(i==n-1 && max1<=cnt)
     {
         max2=max1;
         max1=cnt+1;

     }
     else if(i==n-1 && max2<=cnt)
     {
         max2=cnt+1;
     }
     cnt++;
     }
    //cnt++;

}
//cout<<max1<<endl<<max2<<endl;
//if(max1>max2 && max2>=max1/2) cout<<"NO"<<endl;
if(max1>max2 && (max1%2) && ((max2<(max1+1)/2) || (!max2))) cout<<"YES"<<endl;
else
 {
     cout<<"NO"<<endl;
 }

}//while


return 0;}

Actually in the worst case loop will run N times … so it can be O(N^2)

    vector<int> v(n);
    int z1 = 0, z2 = 0, count = 0;
    for(int i = 0; i < n; i++)
    {
        cin>>v[i];
        if(v[i] == 0)
            count++;
        else
            count = 0;
        
        if(count >= z1)
            z2 = z1, z1 = count;
        else if(count < z1 && count > z2)
            z2 = count;
    }
    
    if(z2 == 0)
        res[i] = z1%2;
    else
    {
        if(z1%2 == 1 || z2 <= (z1-1)/2)
            res[i] = 1;
        else
            res[i] = 0;
    }

Here z1 is the largest zero segment and z2 is the 2nd largest zero segment
Please help…

1 Like

Very nicely written editorial