My issue
Alice will try to remove 2 numbers from odd or even indices while Bob will try to change the parity of sum of odd or even indices.
So, when N = 1 Bob cannot perform the operation but Alice can when the element is greater than 1.
Now check the sum of elements at even and odd indices separately. If they don’t match then Bob will always win because Alice removes 2 always and Bob shifts 1 between indices and so there will be one 1 at the end of all operations.
If they match, then there is a pattern of winning between Alice and Bob (They alternate in winning based on the sum of array and parity of sums of odd and even indices). Find that.
can,anyone explain last pattern when odd and even parity equal
My code
#include<bits/stdc++.h>
#define int long long int
using namespace std;
signed main()
{
int t;
cin>>t;
while(t--){
int n;
cin>>n;
vector<int>v(n);
int odd=0,even=0;
for(int i=0;i<n;i++){
cin>>v[i];
if(v[i]%2)
odd+=v[i];
else
even+=v[i];
}
if(n==1){
cout<<"Bob"<<endl;
continue;
}
int cur=odd+even;
if(cur%2)
cout<<"Bob"<<endl;
else{
cur/=2;
if(cur%2==even%2)
cout<<"Bob"<<endl;
else
cout<<"Alice"<<endl;
}
}
}
Problem Link: Game on Array Practice Coding Problem - CodeChef