#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
#define f first
#define s second
typedef vector<ll> vi;
typedef vector<pi> vpi;
#define pb push_back
#define all(v) v.begin(), v.end()
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll n, a[1000005], b[1000005], arr[1000005], cur, x;
int main() {
fastio; cin >> n;
FOR(i, 0, n-1) {
cin >> a[i] >> b[i];
arr[i] = a[i] - b[i];
if (cur == 0 and arr[i] > 1) {
cur = arr[i];
x = i;
}
}
while (cur > 0) {
while (cur > 1) {
arr[x] = cur % 2;
x = (x+1)%n;
cur /= 2;
if (arr[x] > 0) cur += arr[x];
else if (arr[x] < 0) {
ll t = cur + arr[x];
if (t >= 0) {
arr[x] = 0;
cur = t;
} else {
arr[x] = t;
cur = 0;
}
}
}
FOR(i, 1, n-1) if (arr[(x+i)%n] > 1) {
cur = arr[(x+i)%n]; x = (x+i)%n;
break;
}
}
bool ok = true;
FOR(i, 0, n-1) if (arr[i] != 0) ok = false;
cout << (ok ? "Yes" : "No");
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |