제출 #755653

#제출 시각아이디문제언어결과실행 시간메모리
755653MISM06송금 (JOI19_remittance)C++14
0 / 100
1 ms340 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]; bool be_lock (int idx) { if (a[idx] <= b[idx] + 1ll) return true; return false; } 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]; s -= a[i]; s -= a[(i + 1) % n]; if (x > 0) { x /= 2ll; a[i] -= (2ll * x); a[(i + 1) % n] += x; } s += a[i]; s += a[(i + 1) % n]; int t = be_lock(i); lock -= mark[i]; lock += t; t = be_lock((i + 1) % n); lock -= mark[(i + 1) % n]; lock += t; mark[i] = t; mark[(i + 1) % n] = t; ++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...