제출 #1124570

#제출 시각아이디문제언어결과실행 시간메모리
1124570SharkyCoin Collecting (JOI19_ho_t4)C++20
0 / 100
1 ms328 KiB
#include "bits/stdc++.h" using namespace std; #define int long long const int N = 1e5 + 10; int x[2 * N], y[2 * N]; int f[3][N]; int ans = 0; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<pair<int, int>> v; int cnt = 0; for (int i = 1; i <= 2 * n; i++) { cin >> x[i] >> y[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; } f[x[i]][y[i]]++; if (y[i] == 1) cnt++; } ans += abs(n - cnt); vector<int> d, s; for (int i = 1; i <= n; i++) { for (int j = 1; j <= 2; j++) { if (!f[i][j]) d.push_back(i); else { int delta = f[i][j] - 1; while (delta--) s.push_back(i); } } } for (int i = 0; i < d.size(); i++) ans += abs(d[i] - s[i]); cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...