제출 #755658

#제출 시각아이디문제언어결과실행 시간메모리
755658MISM06Remittance (JOI19_remittance)C++14
100 / 100
221 ms21456 KiB
//0 1 1 0 1 //0 1 0 0 1 //1 0 0 1 1 //0 1 1 0 1 #include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx2") using namespace std; #define F first #define S second #define pb push_back #define sze size() #define all(x) x.begin() , x.end() #define wall__ cout << "--------------------------------------\n"; #define kids int mid = (tl + tr) >> 1, cl = v << 1, cr = v << 1 | 1 #define file_io freopen("input.cpp", "r", stdin); freopen("output.cpp", "w", stdout); typedef long long ll; typedef long double dl; typedef pair < int , int > pii; typedef pair < int , ll > pil; typedef pair < ll , int > pli; typedef pair < ll , ll > pll; typedef pair < int , pii > piii; typedef pair < ll, pll > plll; const ll N = 1e6 + 10; const ll mod = 1e9 + 7; const ll inf = 2e16; const ll rinf = -2e16; const ll INF = 1e9 + 10; const ll rINF = -1e9 - 10; const ll lg = 32; ll a[N], b[N], n; int mark[N]; void solve () { cin >> n; ll s = 0; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; s += a[i]; s -= b[i]; } int lock = 0; int i = 0; while (s > 0 && lock < n) { ll x = a[i] - b[i]; ll k = s; s -= a[i]; s -= a[(i + 1) % n]; if (x > 0) { x /= 2ll; a[i] -= (2ll * x); a[(i + 1) % n] += x; x = a[i] - b[i]; if (x == 1 && b[i] > 0) { a[i] -= 2ll; a[(i + 1) % n] += 1ll; } } s += a[i]; s += a[(i + 1) % n]; if (s == k) ++lock; else lock = 0; ++i; i %= n; } int c = 0; for (int i = 0; i < n; i++) { if (a[i] != b[i]) ++c; } if (c) cout << "No\n"; else cout << "Yes\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) {solve();} return 0; } /* 5 0 0 1 2 2 4 3 2 4 0 */ //shrek will AC this;
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...