Submission #170405

#TimeUsernameProblemLanguageResultExecution timeMemory
170405combi1k1Coin Collecting (JOI19_ho_t4)C++14
100 / 100
67 ms5112 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define X first #define Y second #define all(x) x.begin(),x.end() #define sz(x) (int)x.size() #define pb emplace_back const int N = 1e5 + 1; int a[N][3]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; ll ans = 0; for(int i = 0 ; i < n + n ; ++i) { int x; cin >> x; int y; cin >> y; if (x > n) ans += x - n, x = n; if (x < 1) ans += 1 - x, x = 1; if (y > 2) ans += y - 2, y = 2; if (y < 1) ans += 1 - y, y = 1; a[x][y]++; } int cnt1 = 0; int cnt2 = 0; for(int i = 1 ; i <= n ; ++i) { cnt1 += a[i][1] - 1; cnt2 += a[i][2] - 1; if (cnt1 > 0 && cnt2 < 0) { int x = min(cnt1,-cnt2); ans += x; cnt1 -= x; cnt2 += x; } if (cnt1 < 0 && cnt2 > 0) { int x = min(cnt2,-cnt1); ans += x; cnt1 += x; cnt2 -= x; } ans += abs(cnt1); ans += abs(cnt2); } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...