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 N 1000006
int a[N], b[N];
long long X[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
long long S = 0;
int z_A = 0, z_B = 0;
for(int i = 1; i <= n; ++i) {
cin >> a[i] >> b[i];
if(a[i] == 0) {
++z_A;
}
if(b[i] == 0) {
++z_B;
}
S += (long long)(b[i] - a[i]) << (i - 1);
}
if(z_A == n && z_B == n) {
cout << "Yes";
return 0;
}
if(z_A == n || z_B == n) {
cout << "No";
return 0;
}
if(S % (1 - (1LL << n)) != 0) {
cout << "No";
return 0;
}
X[n] = S / (1 - (1LL << n));
if(X[n] < 0) {
cout << "No";
return 0;
}
X[0] = X[n];
for(int i = 1; i < n; ++i) {
long long val = X[i - 1] + a[i] - b[i];
if(val < 0 || (val & 1)) {
cout << "No";
return 0;
}
X[i] = val >> 1;
}
cout << "Yes";
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... |