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>
using namespace std;
#define int long long
const int modulo = 1e9+7;
int A[7];
int B[7];
int curr[7];
int arr[7];
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for(int i=0;i<n;i++)cin>>A[i]>>B[i];
int start = 0;
int power = 1;
for(int i=1;i<n;i++){
start+=power*(A[i]-B[i]);
power*=2;
}
start+=power*(A[0]-B[0]);
power*=2;
power--;
start/=power;
arr[0]=start;
bool works = true;
for(int x=1;x<n;x++){
arr[x]=arr[x-1]+A[x]-B[x];
if(arr[x]<0)works=false;
if(arr[x]&1)works=false;
arr[x]/=2;
}
int backup = arr[n-1]+A[0]-B[0];
if(backup&1)works=false;
if(arr[0]!=backup/2)works=false;
if(!works)goto shit;
for(int x=0;x<n;x++)curr[x]=A[x];
for(int rounds=1;rounds<40;rounds++){
for(int x=0;x<n;x++){
int uses = min(arr[x],curr[x]/2);
curr[x]-=2*uses;
arr[x]-=uses;
curr[(x+1)%n]+=uses;
}
}
for(int x=0;x<n;x++)if(curr[x]!=B[x])works=false;
if(works){
cout << "Yes\n";
return 0;
}
shit:
cout << "No\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |