제출 #677879

#제출 시각아이디문제언어결과실행 시간메모리
677879puppy송금 (JOI19_remittance)C++17
55 / 100
717 ms32768 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long

int n;
int a[1000005];
int b[1000005];
int x[1000005];
signed main()
{
    cin >> n;
    int tot = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        tot += (1LL << i) * (a[i] - b[i]);
    }
    if (tot % ((1 << n) - 1)) {
        cout << "No\n";
        return 0;
    }
    else x[0] = tot / ((1 << n) - 1);
    for (int i = 0; i < n - 1; i++) {
        int p = x[i] + a[i] - b[i];
        if (p % 2) {
            cout << "No\n";
            return 0;
        }
        else x[i+1] = p / 2;
    }
    bool ok = true;
    for (int i = 0; i < n; i++) ok &= (x[i] >= 0);
    bool ok2 = false;
    for (int i = 0; i < n; i++) ok2 |= (b[i] != 0);
    if (!ok2) {
        ok2 = true;
        for (int i = 0; i < n; i++) ok2 &= (a[i] == 0);
        cout << (ok2 ? "Yes" : "No") << '\n';
    }
    else cout << (ok ? "Yes" : "No") << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...