Submission #133409

#TimeUsernameProblemLanguageResultExecution timeMemory
133409osaaateiasavtnlCoin Collecting (JOI19_ho_t4)C++14
100 / 100
83 ms7416 KiB
#include<bits/stdc++.h> using namespace std; #define int long long const int N = 1e5 + 7; int a[N][3]; signed main() { #ifdef HOME freopen("input.txt", "r", stdin); #else ios_base::sync_with_stdio(0); cin.tie(0); #endif int n; cin >> n; int ans = 0; for (int i = 0; i < 2 * n; ++i) { int x, y; 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]; } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= 2; ++j) { a[i][j] += a[i - 1][j] - 1; } if (a[i][1] > 0 && a[i][2] < 0) { int t = min(abs(a[i][1]), abs(a[i][2])); a[i][1] -= t; a[i][2] += t; ans += t; } if (a[i][1] < 0 && a[i][2] > 0) { int t = min(abs(a[i][1]), abs(a[i][2])); a[i][1] += t; a[i][2] -= t; ans += t; } ans += abs(a[i][1]) + abs(a[i][2]); } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...