Submission #677752

#TimeUsernameProblemLanguageResultExecution timeMemory
677752benedict0724Remittance (JOI19_remittance)C++17
55 / 100
1 ms468 KiB
#include <iostream> #include <stack> #include <string> #include <queue> #include <vector> #include <set> #include <map> #include <algorithm> #include <cassert> using namespace std; typedef long long ll; ll A[22], B[22], C[22]; ll x[22]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int N; cin >> N; for(int i=0;i<N;i++) cin >> A[i] >> B[i]; for(int i=0;i<N;i++) C[i] = A[i] - B[i]; ll X = (1<<N) - 1; bool flag = true; for(int i=0;i<N;i++) { ll tmp = 0; for(int j=0;j<N;j++) { tmp += (1<<j) * C[(i+j+1)%N]; } if(tmp < 0 || tmp%X != 0) flag = false; x[i] = tmp/X; } if(!flag) { cout << "No\n"; return 0; } for(int i=0;i<1000;i++) { for(int j=0;j<N;j++) { if(x[j] > 0 && A[j] > 1) { ll k = min(x[j], A[j]/2); x[j] -= k; A[j] -= 2 * k; A[(j+1)%N] += k; } } } for(int i=0;i<N;i++) if(A[i] != B[i]) flag = false; if(flag) cout << "Yes\n"; else cout << "No\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...