Submission #685350

#TimeUsernameProblemLanguageResultExecution timeMemory
685350flappybirdRemittance (JOI19_remittance)C++17
100 / 100
217 ms51972 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx,avx2,fma") using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; #define MAX 1020200 #define MAXS 20 #define INF 1000000000000000001 #define bb ' ' #define ln '\n' #define Ln '\n' ll A[MAX]; ll B[MAX]; ll d[MAX]; ll X[MAX]; int N; bool chk(ll x0) { X[N] = x0; int i; for (i = N - 1; i >= 0; i--) { X[i] = 2 * X[i + 1] + d[i + 1]; if (X[i] < 0) return false; if (X[i] > 1e18) return false; } for (i = 0; i < N; i++) if (X[i] < 0) return false; return X[0] == X[N]; } signed main() { ios::sync_with_stdio(false), cin.tie(0); cin >> N; ll i; for (i = 0; i < N; i++) cin >> A[i] >> B[i], d[i] = B[i] - A[i]; d[N] = d[0]; ll sum = 0; for (i = 1; i <= min(60, N); i++) sum -= d[N - i + 1] >> i; if (sum < -101010 || sum > 1e10) { cout << "No" << ln; return 0; } if (N <= 20) { sum <<= N; sum /= ((1ll << N) - 1ll); } int c = 0; for (i = sum - 500; i <= sum + 500; i++) { if (chk(i)) { c = 1; break; } } if (!c) { cout << "No" << ln; return 0; } while (1) { int c = 0; for (i = 0; i < N; i++) { if (X[i] && A[i] > 1) { c = 1; ll x = min(X[i], A[i] / 2); X[i] -= x; A[(i + 1) % N] += x; A[i] -= x * 2; } } if (!c) break; } int no = 0; for (i = 0; i < N; i++) if (X[i]) no = 1; if (!no) cout << "Yes" << ln; else cout << "No" << ln; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...