제출 #1136851

#제출 시각아이디문제언어결과실행 시간메모리
1136851onbertRemittance (JOI19_remittance)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int maxn = 1e6 + 5, INF = 1e10; int n; int a[maxn], b[maxn]; signed main() { cin >> n; for (int i=0;i<n;i++) cin >> a[i] >> b[i]; for (int i=1;i<n;i++) { int give = max((a[i] - b[i] + 1) / 2, (int)0); a[i] -= give * 2, a[(i+1)%n] += give; int take = b[i] - a[i]; if (take > 0 && (i > 40 || ((int)1<<i) > INF / take)) {cout << "No\n"; return 0;} a[0] -= take * (1<<i); a[i] += take; if (a[0] < -INF) {cout << "No\n"; return 0;} } if (a[0] > b[0]) { if (n > 40) {cout << "No\n"; return 0;} int diff = a[0] - b[0]; int thing = ((int)1 << n); if (diff % (thing-1) == 0 && a[0] - diff / (thing-1) * thing >= 0) cout << "Yes\n"; else cout << "No\n"; return 0; } if (a[0] == b[0]) 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...