| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1292102 | wedonttalkanymore | Coin Collecting (JOI19_ho_t4) | C++20 | 33 ms | 5140 KiB |
#include <bits/stdc++.h>
/*
Ngay hay dem
Voi troi giac mo em dem
*/
using namespace std;
using ll = long long;
#define int long long
#define pii pair<ll, ll>
#define fi first
#define se second
const ll N = 2e5 + 5, inf = 1e18, mod = 1e9 + 7, block = 320, lim = 19;
int n, x[N], y[N];
int pre[N][2];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
if (fopen(".inp", "r")) {
freopen(".inp", "r", stdin);
freopen(".out", "w", stdout);
}
cin >> n;
int ans = 0;
for (int i = 1; i <= 2 * n; i++) {
cin >> x[i] >> y[i];
if (x[i] >= n) {
ans += x[i] - n;
x[i] = n;
}
else if (x[i] < 1) {
ans += 1 - x[i];
x[i] = 1;
}
if (y[i] >= 2) {
ans += y[i] - 2;
y[i] = 2;
}
else if (y[i] < 1) {
ans += 1 - y[i];
y[i] = 1;
}
pre[x[i]][y[i] - 1]++;
}
for (int i = 1; i <= n; i++) {
pre[i][0]--, pre[i][1]--;
if (pre[i][0] * pre[i][1] < 0) {
if (pre[i][0] < 0) {
int val = min(abs(pre[i][0]), pre[i][1]);
pre[i][0] += val;
pre[i][1] -= val;
ans += val;
}
if (pre[i][1] < 0) {
int val = min(abs(pre[i][1]), pre[i][0]);
pre[i][0] -= val;
pre[i][1] += val;
ans += val;
}
}
ans += abs(pre[i][0]) + abs(pre[i][1]);
pre[i + 1][0] += pre[i][0];
pre[i + 1][1] += pre[i][1];
}
cout << ans;
return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
