이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |