#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int LIM = 1e6;
ll a[LIM + 10];
ll b[LIM + 10];
ll x[LIM + 10];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n;
cin >> n;
ll ans = 0;
for(int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
ans += (b[i] - a[i]) * (1ll << (i - 1));
}
if(ans % ((1ll << n) - 1)) {
cout << "No\n";
}
else {
bool czy = 1;
ans /= ((1ll << n) - 1);
x[n] = ans;
for(int i = n - 1; i >= 1; i--) {
if((a[i] + x[i + 1] - b[i]) & 1) {
czy = 0;
break;
}
else {
x[i] = (a[i] + x[i + 1] - b[i]) / 2;
}
}
if(czy) {
cout << "Yes\n";
}
else {
cout << "No\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |