Submission #683344

#TimeUsernameProblemLanguageResultExecution timeMemory
683344tht2005Remittance (JOI19_remittance)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h>

using namespace std;

#define N 1000006
int a[N], b[N];
long long X[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    long long S = 0;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i] >> b[i];
        S += (long long)(b[i] - a[i]) << (i - 1);
    }
    if(S % (1 - (1LL << n)) != 0) {
        cout << "No";
        return 0;
    }
    X[n] = S / (1 - (1LL << n));
    if(X[n] < 0) {
        cout << "No";
        return 0;
    }
    X[0] = X[n];
    for(int i = 1; i < n; ++i) {
        long long val = X[i - 1] + a[i] - b[i];
        if(val < 0 || (val & 1)) {
            cout << "No";
            return 0;
        }
        X[i] = val >> 1;
    }
    cout << "Yes";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...