# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
99049 | 2019-02-28T08:02:37 Z | 크리(#2856, kriii) | Coin Collecting (JOI19_ho_t4) | C++17 | 3 ms | 384 KB |
#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++){ if (r[0] + r[1] < 0){ int x = min(-r[0],C[i][0]); int y = min(-r[1],C[i][1]); r[0] += x; C[i][0] -= x; r[1] += y; C[i][1] -= y; int z = min(-r[0]-r[1],C[i][0]+C[i][1]), t=z; ans += z + (x + y + z) * 1ll * i; while (r[0] < 0 && z > 0) r[0]++, z--; while (r[1] < 0 && z > 0) r[1]++, z--; z = t; while (C[i][0] > 0 && z > 0) C[i][0]--, z--; while (C[i][1] > 0 && z > 0) C[i][1]--, z--; } r[0] += C[i][0]; r[1] += C[i][1]; ans -= (C[i][0] + C[i][1]) * 1ll * i; bool see[2] = {0,}; for (int k=0;k<2;k++){ if (r[k] > 0){ ans += i; r[k]--; see[k] = 1; } } for (int k=0;k<2;k++){ if (!see[k] && r[!k] > 0){ ans += i + 1; r[!k]--; see[k] = 1; } } for (int k=0;k<2;k++){ if (!see[k]){ r[k]--; ans -= i; } } } printf ("%lld\n",ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 3 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Incorrect | 1 ms | 256 KB | Output isn't correct |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 3 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Incorrect | 1 ms | 256 KB | Output isn't correct |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 3 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Incorrect | 1 ms | 256 KB | Output isn't correct |
10 | Halted | 0 ms | 0 KB | - |