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 ll long long
using namespace std;
int a[9],b[9],s,n,dp[10][10][10][10][10][10][10];
void check(int x[7])
{
for(int i=0;i<n;i++)
{
if(x[i]==b[i])continue;
else return;
}
cout<<"YES";
exit(0);
}
void bt(int x[7],int sm)
{
if(sm<s)return;
if(dp[x[0]][x[1]][x[2]][x[3]][x[4]][x[5]][x[6]])return;
//for(int i=0;i<n;i++)cout<<x[i]<<" ";cout<<"\n";
if(sm==s)
{
check(x);
return;
}
for(int i=0;i<n;i++)
{
if(x[i]<=1)continue;
x[i]-=2;
x[(i+1)%n]++;
bt(x,sm-1);
x[(i+1)%n]--;
x[i]+=2;
}
dp[x[0]][x[1]][x[2]][x[3]][x[4]][x[5]][x[6]]=1;
return;
}
int sm;
int main()
{
cin>>n;
while(1)sm++;
for(int i=0;i<n;i++)
{
cin>>a[i]>>b[i];
sm+=a[i];
s+=b[i];
}
bt(a,sm);
cout<<"NO";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |