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;
void solve() {
int n;
cin >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
}
long long denom = (1ll << n) - 1;
vector<long long> x(n);
for (int i = 0; i < n; ++i) {
for (int j = i; j >= 0; --j) {
x[i] = 2 * x[i] + b[j] - a[j];
}
for (int j = n - 1; j > i; --j) {
x[i] = 2 * x[i] + b[j] - a[j];
}
x[i] = -x[i];
if (x[i] < 0 || x[i] % denom != 0) {
cout << "No\n";
return;
}
x[i] /= denom;
}
bool change = true;
while (change) {
change = false;
for (int i = 0; i < n; ++i) {
if (x[i] > 0 && a[i] >= 2) {
change = true;
long long trans = min(x[i], a[i] * 1ll / 2);
x[i] -= trans;
a[i] -= 2 * trans;
int nxt = i + 1;
if (nxt == n) {
nxt = 0;
}
a[nxt] += trans;
}
}
}
for (int i = 0; i < n; ++i) {
if (x[i] != 0) {
cout << "No\n";
return;
}
}
cout << "Yes\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int T = 1;
cin >> T;
while (T--) {
solve();
cerr << "-----------\n";
cout << "-----------\n";
}
#else
int T = 1;
// cin >> T;
while (T--) {
solve();
}
#endif
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... |