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