#include<bits/stdc++.h>
using namespace std;
long long mod=1e9+7;
int n,a[10],b[10];
bool t=false;
void f(int num)
{
if(num==5)return;
bool tt=true;
for(int i=0; i<n; i++)
{
if(a[i]!=b[i])tt=false;
}
t=tt;
if(t==true)
{
cout<<"YES";
exit(0);
}
for(int i=0; i<n; i++)
{
for(int j=0; j<=a[i]; j+=2)
{
if(i!=0)
{
a[i]-=j;
a[i-1]+=j/2;
f(num+1);
a[i]+=j;
a[i-1]-=j/2;
}
else
{
a[i]-=j;
a[n-1]+=j/2;
f(num+1);
a[i]+=j;
a[n-1]-=j/2;
}
if(i!=n-1)
{
a[i]-=j;
a[i+1]+=j/2;
f(num+1);
a[i]+=j;
a[i+1]-=j/2;
}
else
{
a[i]-=j;
a[0]+=j/2;
f(num+1);
a[i]+=j;
a[0]-=j/2;
}
}
}
}
int main()
{
cin>>n;
for(int i=0; i<n; i++)cin>>a[i]>>b[i];
f(0);
cout<<"NO";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
62 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
62 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
62 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |