Submission #1302017

#TimeUsernameProblemLanguageResultExecution timeMemory
1302017TymondRemittance (JOI19_remittance)C++20
100 / 100
203 ms20316 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define fi first #define se second int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; vector<pair<ll, ll>> a(n); vector<bool> on_queue(n, false); queue<int> q; for(int i = 0; i < n; i++){ cin >> a[i].fi >> a[i].se; if(a[i].fi > a[i].se){ q.push(i); on_queue[i] = true; } } while(q.size()){ int v = q.front(); q.pop(); on_queue[v] = false; int nxt = (v == n - 1 ? 0 : v + 1); if(a[v].fi > 1){ int dod = (a[v].fi - a[v].se) / 2; a[v].fi -= (2 * dod); a[nxt].fi += dod; if(a[nxt].fi > a[nxt].se + 1 && on_queue[nxt] == false){ on_queue[nxt] = true; q.push(nxt); } } } bool all1 = true; bool isNone1 = false; for(int i = 0; i < n; i++){ if(a[i].fi - a[i].se != 1){ all1 = false; } if(a[i].fi != 1){ isNone1 = true; } } if(all1 && isNone1){ cout << "Yes\n"; return 0; } bool ok = true; for(int i = 0; i < n; i++){ if(a[i].fi != a[i].se){ ok = false; } } if(ok){ cout << "Yes\n"; }else{ cout << "No\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...