제출 #1126434

#제출 시각아이디문제언어결과실행 시간메모리
1126434usukhbaatarCoin Collecting (JOI19_ho_t4)C++20
100 / 100
137 ms1988 KiB
#include <bits/stdc++.h> #define int long long using namespace std; int32_t main() { int n; cin >> n; array<vector<int>, 2> a = { vector<int>(n, -1), vector<int>(n, -1) }; int ans = 0; for (int i = 0; i < 2 * n; i++) { int x, y; cin >> x >> y; x--; y--; int xx = min(max(x, 0LL), n - 1); int yy = min(max(y, 0LL), 1LL); ans += abs(x - xx) + abs(y - yy); a[yy][xx]++; } int s[2]{}; for (int i = 0; i < n; i++) { s[0] += a[0][i]; s[1] += a[1][i]; if (s[0] < 0 && s[1] > 0) { int d = min(s[1], -s[0]); ans += d; s[0] += d; s[1] -= d; } if (s[0] > 0 && s[1] < 0) { int d = min(s[0], -s[1]); ans += d; s[0] -= d; s[1] += d; } ans += abs(s[0]); ans += abs(s[1]); } cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...