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;
const int N = 1000000;
long long a[N], b[N], c[N], d[N];
long long calc(long long *poly, long long *sum, int n) {
copy(poly, poly + n, sum);
long long carry = 0, whole = 0;
do {
for (int i = 0; i < n; ++i) {
sum[i] += carry;
carry = sum[i] / 2;
sum[i] %= 2;
}
whole += carry;
} while (carry > 0);
if (count(sum, sum + n, 1) == n) {
fill(sum, sum + n, 0);
++whole;
}
return whole;
}
int 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];
}
if (*max_element(b, b + n) == 0 && *max_element(a, a + n) > 0) {
cout << "No\n";
exit(0);
}
long long flow = calc(a, c, n) - calc(b, d, n);
if (!equal(c, c + n, d)) {
cout << "No\n";
exit(0);
}
for (int i = 0; i < n; ++i) {
flow = (flow + a[i] - b[i]) / 2;
if (flow < 0) {
cout << "No\n";
exit(0);
}
}
cout << "Yes\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... |