# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1202166 | nguyn | Coin Collecting (JOI19_ho_t4) | C++20 | 26 ms | 3144 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define pii pair<int,int>
const int N = 2e5 + 5;
int cnt[N][3];
int x[N], y[N], n;
signed main(){
ios_base::sync_with_stdio(false) ;
cin.tie(0) ; cout.tie(0) ;
if (fopen("INP.INP" ,"r")) {
freopen("INP.INP" ,"r" , stdin) ;
freopen("OUT.OUT" , "w" , stdout) ;
}
cin >> n;
ll res = 0;
for (int i = 1; i <= 2 * n; i++) {
cin >> x[i] >> y[i];
if (x[i] < 1) {
res += 1 - x[i];
x[i] = 1;
}
if (x[i] > n) {
res += x[i] - n;
x[i] = n;
}
if (y[i] < 1) {
res += 1 - y[i];
y[i] = 1;
}
if (y[i] > 2) {
res += y[i] - 2;
y[i] = 2;
}
cnt[x[i]][y[i]]++;
}
for (int i = 1; i <= n; i++) {
int change = min(max(0, cnt[i][1] - 1), max(0, 1 - cnt[i][2]));
cnt[i][1] -= change;
cnt[i][2] += change;
res += change;
change = min(max(0, 1 - cnt[i][1]), max(0, cnt[i][2] - 1));
cnt[i][1] += change;
cnt[i][2] -= change;
res += change;
res += abs(cnt[i][1] - 1);
cnt[i + 1][1] += cnt[i][1] - 1;
res += abs(cnt[i][2] - 1);
cnt[i + 1][2] += cnt[i][2] - 1;
}
cout << res;
}
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... |