Submission #1331848

#TimeUsernameProblemLanguageResultExecution timeMemory
1331848kawhietRemittance (JOI19_remittance)C++20
0 / 100
1 ms368 KiB
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 47
#endif

#define int long long

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < n; i++) {
        auto x = a, y = b;
        bool ok = 1;
        for (int j = i; j < n; j++) {
            if (x[j] < y[j] || (x[j] - y[j]) % 2 == 1) {
                ok = 0;
                break;
            }
            int k = (x[i] - y[j]) / 2;
            x[(j + 1) % n] += k;
            x[j] -= 2 * k;
        }
        for (int j = 0; j < i; j++) {
            if (x[j] < y[j] || (x[j] - y[j]) % 2 == 1) {
                ok = 0;
                break;
            }
            int k = (x[j] - y[j]) / 2;
            x[(j + 1) % n] += k;
            x[j] -= 2 * k;
        }
        if (x == y) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...