Submission #100981

#TimeUsernameProblemLanguageResultExecution timeMemory
100981Alexa2001Coin Collecting (JOI19_ho_t4)C++17
100 / 100
95 ms5024 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int Nmax = 1e5 + 5; int a[Nmax][3], s[3], wait[3], n; ll ans = 0; void read() { int x, y, i; cin >> n; for(i=1; i<=2*n; ++i) { cin >> x >> y; if(x < 1) ans += 1 - x, x = 1; if(x > n) ans += x - n, x = n; if(y < 1) ans += 1 - y, y = 1; if(y > 2) ans += y - 2, y = 2; ++a[x][y]; } } void solve() { int i, j, k1, k2; k1 = 1; k2 = 0; for(i=1; i<=n; ++i) for(j=0; j<a[i][1] + a[i][2]; ++j) { if(k1 < i) ans += i - k1; else if(k1 > i) ans += k1 - i; if(k2) ++k1; k2 ^= 1; } for(i=1; i<=n; ++i) { ++wait[1]; ++wait[2]; s[1] += a[i][1]; s[2] += a[i][2]; while(wait[1] && s[1]) --wait[1], --s[1]; while(wait[2] && s[2]) --wait[2], --s[2]; while(wait[1] && s[2]) --wait[1], --s[2], ++ans; while(wait[2] && s[1]) --wait[2], --s[1], ++ans; } cout << ans << '\n'; } int main() { // freopen("input", "r", stdin); cin.sync_with_stdio(false); read(); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...