Submission #127711

#TimeUsernameProblemLanguageResultExecution timeMemory
127711IOrtroiiiCoin Collecting (JOI19_ho_t4)C++14
100 / 100
101 ms6020 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; vector<vector<int>> cnt(n, vector<int>(2)); vector<int> f(2); long long ans = 0; for (int i = 0; i < 2 * n; ++i) { int x, y; cin >> x >> y; --x, --y; if (x < 0) { ans -= x; x = 0; } else if (x > n - 1) { ans += x - n + 1;; x = n - 1; } if (y < 0) { ans -= y; y = 0; } else if (y > 1) { ans += y - 1; y = 1; } ++cnt[x][y]; } for (int i = 0; i < n; ++i) { for (int j = 0; j < 2; ++j) { f[j] += cnt[i][j] - 1; } for (int j = 0; j < 2; ++j) { if (f[j] > 0 && f[j ^ 1] < 0) { int cur = min(f[j], -f[j ^ 1]); ans += cur; f[j] -= cur; f[j ^ 1] += cur; } } for (int j = 0; j < 2; ++j) { ans += abs(f[j]); } } printf("%lld\n", ans); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...