This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN=1e5+10;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
int n,k;
int a[11];
short used[3][3][3][3][3][3][3][3][3][3][3];
/// 0 - not used
/// 1 - yes
/// 2 - no
void read()
{
for(int i=1; i<=n; i++)
cin>>a[i];
}
long long sum=0;
void read2()
{
long long x;
for(int i=1;i<=n;i++)
{
cin>>x;
sum+=x;
}
}
short wins(int s[11],int maxmove)
{
maxmove=min(maxmove,3);
//cout<<s[1]<<" "<<s[2]<<" "<<s[3]<<" "<<s[4]<<" "<<s[5]<<" "<<s[6]<<" "<<s[7]<<" "<<s[8]<<" "<<s[9]<<" "<<s[10]<<", moves: "<<maxmove<<": "<<used[s[1]][s[2]][s[3]][s[4]][s[5]][s[6]][s[7]][s[8]][s[9]][s[10]][maxmove]<<endl;
if(used[s[1]][s[2]][s[3]][s[4]][s[5]][s[6]][s[7]][s[8]][s[9]][s[10]][maxmove]!=0)
{
//cout<<s[1]<<" "<<s[2]<<" "<<s[3]<<" "<<s[4]<<" "<<s[5]<<" "<<s[6]<<" "<<s[7]<<" "<<s[8]<<" "<<s[9]<<" "<<s[10]<<", moves: "<<maxmove<<": "<<used[s[1]][s[2]][s[3]][s[4]][s[5]][s[6]][s[7]][s[8]][s[9]][s[10]][maxmove]<<endl;
return used[s[1]][s[2]][s[3]][s[4]][s[5]][s[6]][s[7]][s[8]][s[9]][s[10]][maxmove];
}
bool emptyy=true;
for(int i=1; i<=n; i++)
{
if(s[i]!=0)emptyy=false;
}
if(emptyy==true)
{
used[0][0][0][0][0][0][0][0][0][0][maxmove]=2;
return 2;
}
for(int i=1; i<=n; i++)
{
int old=s[i];
for(int take=1; take<=min(s[i],maxmove); take++)
{
s[i]-=take;
if(wins(s,take)==2)
{
s[i]=old;
used[s[1]][s[2]][s[3]][s[4]][s[5]][s[6]][s[7]][s[8]][s[9]][s[10]][maxmove]=1;
return used[s[1]][s[2]][s[3]][s[4]][s[5]][s[6]][s[7]][s[8]][s[9]][s[10]][maxmove];
}
s[i]=old;
}
}
used[s[1]][s[2]][s[3]][s[4]][s[5]][s[6]][s[7]][s[8]][s[9]][s[10]][min(maxmove,3)]=2;
return used[s[1]][s[2]][s[3]][s[4]][s[5]][s[6]][s[7]][s[8]][s[9]][s[10]][min(maxmove,3)];
}
int main()
{
speed();
int t;
cin>>t;
while(t--)
{
cin>>n>>k;
if(k==1)
{
sum=0;
read2();
cout<<sum%2;
}
else
{
read();
if(wins(a,k)==true)cout<<1;
else cout<<0;
}
}
cout<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |