Submission #591255

#TimeUsernameProblemLanguageResultExecution timeMemory
591255piOOECoin Collecting (JOI19_ho_t4)C++17
0 / 100
1 ms408 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<vector<int>> a(2, vector<int>(n)), b(2, vector<int>(n, 1)); ll ans = 0; for (int i = 0; i < 2 * n; ++i) { int x, y; cin >> x >> y; if (y >= 2) { ans += y - 2; y = 2; } else { ans += 1 - y; y = 1; } if (x < 1) { ans += 1 - x; x = 1; } else if (x > n) { ans += x - n; x = n; } ++a[y - 1][x - 1]; } array<int, 2> d{}; for (int i = 0; i < n; ++i) { for (int t = 0; t < 2; ++t) { if (b[t][i]) { d[t] -= 1; } if (a[t][i]) { d[t] += 1; } } if (d[0] < 0 && d[1] > 0) { int mn = min(-d[0], d[1]); d[0] += mn; d[1] -= mn; ans += mn; } else if (d[1] < 0 && d[0] > 0) { int mn = min(-d[1], d[0]); d[1] += mn; d[0] -= mn; ans += mn; } ans += abs(d[0] + d[1]); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...