# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
334796 | ChrisT | Coin Collecting (JOI19_ho_t4) | C++17 | 69 ms | 4972 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MN = 1e5 + 5;
int ree[MN][3];
int main() {
int n;
scanf ("%d",&n); long long ret = 0;
for (int i = 1; i <= 2 * n; i++) {
int x,y;
scanf ("%d %d",&x,&y);
if (x < 1) ret += 1-x, x=1;
if (x > n) ret += x-n, x=n;
if (y < 1) ret += 1-y, y=1;
if (y > 2) ret += y-2, y=2;
++ree[x][y];
}
int cnt01=0, cnt02=0, cnt11=0, cnt12=0;
for (int i = 1; i <= n; i++) {
if (!ree[i][1]) { //blue 1
++cnt01;
}
if (!ree[i][2]) { //blue 2
++cnt02;
}
while (ree[i][1] > 1) { //red 1
++cnt11;
--ree[i][1];
}
while (ree[i][2] > 1) { //red 2
++cnt12;
--ree[i][2];
}
while (cnt01 && cnt11) {
cnt01--; cnt11--;
}
while (cnt02 && cnt12) {
cnt02--; cnt12--;
}
while (cnt01 && cnt12) {
cnt01--; cnt12--; ret++;
}
while (cnt02 && cnt11) {
cnt02--; cnt11--; ret++;
}
ret += cnt01 + cnt02 + cnt11 + cnt12;
}
printf ("%lld\n",ret);
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... |