Submission #912115

#TimeUsernameProblemLanguageResultExecution timeMemory
912115yellowtoadRemittance (JOI19_remittance)C++17
100 / 100
617 ms36580 KiB
#include <iostream> using namespace std; long long n, a[1000010], b[1000010], cnt; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; if (a[i] != b[i]) cnt++; } for (int i = 1; i <= 50; i++) { if (cnt == 0) { cout << "Yes" << endl; return 0; } for (int j = 1; j < n; j++) { if (a[j] > b[j]) { if (a[j+1] == b[j+1]) cnt++; a[j+1] += (a[j]-max(0LL,b[j]-1))/2; if (a[j+1] == b[j+1]) cnt--; a[j] -= (a[j]-max(0LL,b[j]-1))/2*2; if (a[j] == b[j]) cnt--; } } if (a[n] > b[n]) { if (a[1] == b[1]) cnt++; a[1] += (a[n]-max(0LL,b[n]-1))/2; if (a[1] == b[1]) cnt--; a[n] -= (a[n]-max(0LL,b[n]-1))/2*2; if (a[n] == b[n]) cnt--; } /*for (int j = 1; j <= n; j++) cout << a[j] << " " << b[j] << endl; cout << endl;*/ } if (cnt == 0) cout << "Yes" << endl; else cout << "No" << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...