# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
99069 | kriii | Coin Collecting (JOI19_ho_t4) | C++17 | 102 ms | 1500 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 <stdio.h>
#include <algorithm>
#include <queue>
using namespace std;
int N, C[100100][2];
int main()
{
long long ans = 0;
scanf ("%d",&N);
for (int i=0;i<N*2;i++){
int x,y;
scanf ("%d %d",&x,&y);
if (x < 1) ans += 1 - x, x = 1;
if (x > N) ans += x - N, x = N;
if (y < 1) ans += 1 - y, y = 1;
if (y > 2) ans += y - 2, y = 2;
C[x][y-1]++;
}
int r[2] = {0,};
for (int i=1;i<=N;i++){
r[0] += C[i][0] - 1;
r[1] += C[i][1] - 1;
for (int k=0;k<2;k++) if (r[k] > 0 && r[!k] < 0){
int x = min(r[k], -r[!k]);
ans += x;
r[k] -= x;
r[!k] += x;
}
ans += abs(r[0]) + abs(r[1]);
}
printf ("%lld\n",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... |