제출 #1148958

#제출 시각아이디문제언어결과실행 시간메모리
1148958Issa송금 (JOI19_remittance)C++20
15 / 100
107 ms464 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define ent "\n" const int maxn = 1e6 + 100; const ll INF = (ll)1e18 + 100; const int inf = 1e7 + 100; const ll MOD = 1e9 + 7; const int maxl = 16; const ll P = 31; int n; ll a[maxn]; ll b[maxn]; ll d[maxn]; ll c[maxn]; void test(){ cin >> n; ll sum = 0, ok = 1; for(int i = 0; i < n; i++){ cin >> a[i] >> b[i]; sum += b[i]; ok &= a[i] == b[i]; } a[n] = a[0]; b[n] = b[0]; if(ok){ cout << "Yes\n"; return; } if(!sum){ cout << "No\n"; return; } for(int i = 0; i < n; i++){ if(1 & (a[i+1] ^ b[i+1])) c[i] = 1; } c[n] = c[0]; for(int k = 1; k < 50; k++){ for(int i = 0; i < n; i++){ if(((c[i] + a[i+1] - b[i+1])>>1) % (1ll<<k) != c[i+1]){ c[i] |= (1ll<<k); } } c[n] = c[0]; } for(int _ = 0, i = 0; _ < n * 1000000; _++){ int j = (i + 1) % n; ll cnt = min(a[i] / 2, c[i]); a[i] -= cnt * 2; c[i] -= cnt; a[j] += cnt; i = j; } for(int i = 0; i < n; i++){ if(a[i] != b[i]){ cout << "No\n"; return; } } cout << "Yes\n"; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; t = 1; while(t--) test(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...