| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1338799 | riafhasan2010 | Coin Collecting (JOI19_ho_t4) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 7;
int v[N][3];
int n;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
v[n * 3][1] = v[n * 3][2] = n * 2;
ll ans = 0;
for (int i = 1; i <= n * 2; i++) {
int x, y; cin >> x >> y;
if (x >= 1 and x <= n and y >= 1 and y <= 2) {
v[x][y]++;
}
else if (x >= 1 and x <= n) {
if (y > 2) {
ans += abs(y - 2);
y = 2;
}
else {
ans += abs(1 - y);
y = 1;
}
v[x][y]++;
}
else if (y >= 1 and y <= 2) {
if (x > n) {
ans += abs(n - x);
x = n;
}
else {
ans += abs(1 - x);
x = 1;
}
v[x][y]++;
}
else {
if (x <= 0 and y <= 0) {
ans += abs(x - 1);
ans += abs(y - 1);
v[1][1]++;
}
else if (x > n and y <= 0) {
ans += abs(x - n);
ans += abs(y - 1);
v[n][1]++;
}
else if (x <= 0 and y > 2) {
ans += abs(x - 1);
ans += abs(y - 2);
v[1][2]++;
}
else {
ans += abs(x - n);
ans += abs(y - 2);
v[n][2]++;
}
}
}
vector<pair<int, int>>
cout << ans << '\n';
}
