Submission #683346

#TimeUsernameProblemLanguageResultExecution timeMemory
683346tht2005Remittance (JOI19_remittance)C++17
55 / 100
242 ms35496 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; int z_A = 0, z_B = 0; for(int i = 1; i <= n; ++i) { cin >> a[i] >> b[i]; if(a[i] == 0) { ++z_A; } if(b[i] == 0) { ++z_B; } S += (long long)(b[i] - a[i]) << (i - 1); } if(z_A == n && z_B == n) { cout << "Yes"; return 0; } if(z_A == n || z_B == n) { cout << "No"; return 0; } 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...