제출 #564201

#제출 시각아이디문제언어결과실행 시간메모리
5642014fecta송금 (JOI19_remittance)C++17
15 / 100
251 ms16096 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)

const int MN = 1000005;

int n;
pii a[MN * 2];

int fpow(int b, int p, int mod) {
    if (!p) return 1;
    int ret = fpow(b, p / 2, mod);
    if (p & 1) return ret * ret % mod * b % mod;
    return ret * ret % mod;
}

int32_t main() {
    boost();

    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i].f >> a[i].s;
    for (int i = 0; i < MN; i++) {
        if (a[i].s > a[i].f) {
            int d = a[i].s - a[i].f;
            a[i].s -= d;
            a[i + n].s += d;
        }
        int d = a[i].f - a[i].s;
        int tk = min(a[i].f / 2, (d + 1) / 2);
        a[i].f -= tk * 2;
        a[i + 1].f += tk;
        if (a[i].s > a[i].f) {
            int d = a[i].s - a[i].f;
            a[i].s -= d;
            a[i + n].s += d;
        }
        if (a[i].f > a[i].s) {
            int d = a[i].f - a[i].s;
            a[i].f -= d;
            a[i + n].f += d;
        }
    }
    int was = (1ll << n) - 1, sum = 0;
    for (int i = 0; i < MN * 2; i++) {
        assert(a[i].f >= 0 && a[i].s >= 0);
        if (a[i].f != a[i].s) return 0 * printf("No\n");
        sum += fpow(2, i, was) * (a[i].f - a[i].s) % was;
    }
    if (sum % was == 0) printf("Yes\n");
    else printf("No\n");

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...