Submission #997308

#TimeUsernameProblemLanguageResultExecution timeMemory
997308yanbCoin Collecting (JOI19_ho_t4)C++14
100 / 100
42 ms13648 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<long long, long long> #define t3i tuple<long long, long long, long long> signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> x(2 * n), y(2 * n); for (int i = 0; i < 2 * n; i++) cin >> x[i] >> y[i]; int ans = 0; for (int i = 0; i < 2 * n; i++) { if (x[i] < 1) ans += 1 - x[i], x[i] = 1; if (x[i] > n) ans += x[i] - n, x[i] = n; if (y[i] < 1) ans += 1 - y[i], y[i] = 1; if (y[i] > 2) ans += y[i] - 2, y[i] = 2; } vector<vector<int>> q(n, vector<int>(2, -1)); for (int i = 0; i < 2 * n; i++) q[x[i] - 1][y[i] - 1]++; for (int i = 0; i < n; i++) { if (q[i][0] > 0 && q[i][1] < 0) { int d = min(q[i][0], -q[i][1]); ans += d; q[i][0] -= d, q[i][1] += d; } if (q[i][0] < 0 && q[i][1] > 0) { int d = min(-q[i][0], q[i][1]); ans += d; q[i][0] += d, q[i][1] -= d; } if (i < n - 1) { q[i + 1][0] += q[i][0], q[i + 1][1] += q[i][1]; ans += abs(q[i][0]) + abs(q[i][1]); q[i][0] = q[i][1] = 0; } } /*for (int i = 0; i < 2; i++) { for (int j = 0; j < n; j++) { cout << q[j][i] << "\t"; } cout << "\n"; }*/ cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...