# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
99053 | 2019-02-28T08:19:15 Z | 조승현(#2855, ainta) | Coin Collecting (JOI19_ho_t4) | C++17 | 24 ms | 12672 KB |
#include<cstdio> #include<algorithm> #include<vector> #define N_ 2010 using namespace std; long long res; struct point { int x, y; }w[N_]; int C[N_][2], n, S[N_], T[N_]; int CK[N_]; vector<int>U[2]; long long D[N_][N_]; int main() { int i, j, k; scanf("%d", &n); for (i = 1; i <= n * 2; i++) { scanf("%d%d", &w[i].x, &w[i].y); if (w[i].x < 1) { res += 1 - w[i].x; w[i].x = 1; } if (w[i].x > n) { res += w[i].x - n; w[i].x = n; } if (w[i].y < 1) { res += 1 - w[i].y; w[i].y = 1; } if (w[i].y > 2) { res += w[i].y - 2; w[i].y = 2; } C[w[i].x][w[i].y - 1]++; } for (i = 1; i <= n; i++) { S[i] = S[i - 1] + C[i][0] + C[i][1]; T[i] = S[i] - i * 2; } for (i = 1; i <= n; i++) { for (j = 0; j < 2; j++) { for (k = 0; k < C[i][j]; k++) { U[j].push_back(i); } } } int n1 = U[0].size(), n2 = U[1].size(); for (i = 0; i <= n1; i++) { for (j = 0; j <= n2; j++) { D[i][j] = 1e18; } } D[0][0] = 0; for (i = 0; i <= n1; i++) { for (j = 0; j <= n2; j++) { long long t = D[i][j]; if (t > 1e17)continue; int x = (i + j) / 2 + 1; if (i <= n1 - 2) { D[i + 2][j] = min(D[i + 2][j], t + 1 + abs(U[0][i] - x) + abs(U[0][i + 1] - x)); } if (j <= n2 - 2) { D[i][j + 2] = min(D[i][j + 2], t + 1 + abs(U[1][j] - x) + abs(U[1][j + 1] - x)); } if (i != n1 && j != n2) { D[i + 1][j + 1] = min(D[i + 1][j + 1], t + abs(U[0][i] - x) + abs(U[1][j] - x)); } } } printf("%lld\n", D[n1][n2] + res); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 3 ms | 384 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 | 384 KB | Output is correct |
9 | Correct | 2 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
11 | Correct | 2 ms | 384 KB | Output is correct |
12 | Correct | 2 ms | 384 KB | Output is correct |
13 | Correct | 2 ms | 384 KB | Output is correct |
14 | Correct | 2 ms | 384 KB | Output is correct |
15 | Correct | 2 ms | 384 KB | Output is correct |
16 | Correct | 3 ms | 384 KB | Output is correct |
17 | Correct | 3 ms | 384 KB | Output is correct |
18 | Correct | 2 ms | 384 KB | Output is correct |
19 | Correct | 2 ms | 384 KB | Output is correct |
20 | Correct | 2 ms | 384 KB | Output is correct |
21 | Correct | 3 ms | 384 KB | Output is correct |
22 | Correct | 2 ms | 384 KB | Output is correct |
23 | Correct | 2 ms | 384 KB | Output is correct |
24 | Correct | 2 ms | 384 KB | Output is correct |
25 | Correct | 3 ms | 256 KB | Output is correct |
26 | Correct | 3 ms | 384 KB | Output is correct |
27 | Correct | 2 ms | 384 KB | Output is correct |
28 | Correct | 2 ms | 384 KB | Output is correct |
29 | Correct | 2 ms | 384 KB | Output is correct |
30 | Correct | 3 ms | 384 KB | Output is correct |
31 | Correct | 2 ms | 384 KB | Output is correct |
32 | Correct | 2 ms | 384 KB | Output is correct |
33 | Correct | 2 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 3 ms | 384 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 | 384 KB | Output is correct |
9 | Correct | 2 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
11 | Correct | 2 ms | 384 KB | Output is correct |
12 | Correct | 2 ms | 384 KB | Output is correct |
13 | Correct | 2 ms | 384 KB | Output is correct |
14 | Correct | 2 ms | 384 KB | Output is correct |
15 | Correct | 2 ms | 384 KB | Output is correct |
16 | Correct | 3 ms | 384 KB | Output is correct |
17 | Correct | 3 ms | 384 KB | Output is correct |
18 | Correct | 2 ms | 384 KB | Output is correct |
19 | Correct | 2 ms | 384 KB | Output is correct |
20 | Correct | 2 ms | 384 KB | Output is correct |
21 | Correct | 3 ms | 384 KB | Output is correct |
22 | Correct | 2 ms | 384 KB | Output is correct |
23 | Correct | 2 ms | 384 KB | Output is correct |
24 | Correct | 2 ms | 384 KB | Output is correct |
25 | Correct | 3 ms | 256 KB | Output is correct |
26 | Correct | 3 ms | 384 KB | Output is correct |
27 | Correct | 2 ms | 384 KB | Output is correct |
28 | Correct | 2 ms | 384 KB | Output is correct |
29 | Correct | 2 ms | 384 KB | Output is correct |
30 | Correct | 3 ms | 384 KB | Output is correct |
31 | Correct | 2 ms | 384 KB | Output is correct |
32 | Correct | 2 ms | 384 KB | Output is correct |
33 | Correct | 2 ms | 384 KB | Output is correct |
34 | Correct | 19 ms | 12288 KB | Output is correct |
35 | Correct | 11 ms | 8348 KB | Output is correct |
36 | Correct | 16 ms | 12160 KB | Output is correct |
37 | Correct | 19 ms | 12288 KB | Output is correct |
38 | Correct | 20 ms | 12288 KB | Output is correct |
39 | Correct | 19 ms | 12284 KB | Output is correct |
40 | Correct | 18 ms | 12288 KB | Output is correct |
41 | Correct | 17 ms | 12288 KB | Output is correct |
42 | Correct | 17 ms | 12288 KB | Output is correct |
43 | Correct | 17 ms | 12264 KB | Output is correct |
44 | Correct | 21 ms | 12288 KB | Output is correct |
45 | Correct | 17 ms | 12288 KB | Output is correct |
46 | Correct | 17 ms | 12160 KB | Output is correct |
47 | Correct | 24 ms | 12288 KB | Output is correct |
48 | Correct | 15 ms | 12416 KB | Output is correct |
49 | Correct | 17 ms | 12160 KB | Output is correct |
50 | Correct | 16 ms | 12288 KB | Output is correct |
51 | Correct | 16 ms | 12288 KB | Output is correct |
52 | Correct | 17 ms | 12288 KB | Output is correct |
53 | Correct | 10 ms | 8448 KB | Output is correct |
54 | Correct | 16 ms | 10368 KB | Output is correct |
55 | Correct | 7 ms | 3200 KB | Output is correct |
56 | Correct | 3 ms | 384 KB | Output is correct |
57 | Correct | 8 ms | 3584 KB | Output is correct |
58 | Correct | 16 ms | 10880 KB | Output is correct |
59 | Correct | 16 ms | 12544 KB | Output is correct |
60 | Correct | 22 ms | 12672 KB | Output is correct |
61 | Correct | 21 ms | 11264 KB | Output is correct |
62 | Correct | 16 ms | 10680 KB | Output is correct |
63 | Correct | 15 ms | 9984 KB | Output is correct |
64 | Correct | 13 ms | 7808 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 3 ms | 384 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 | 384 KB | Output is correct |
9 | Correct | 2 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
11 | Correct | 2 ms | 384 KB | Output is correct |
12 | Correct | 2 ms | 384 KB | Output is correct |
13 | Correct | 2 ms | 384 KB | Output is correct |
14 | Correct | 2 ms | 384 KB | Output is correct |
15 | Correct | 2 ms | 384 KB | Output is correct |
16 | Correct | 3 ms | 384 KB | Output is correct |
17 | Correct | 3 ms | 384 KB | Output is correct |
18 | Correct | 2 ms | 384 KB | Output is correct |
19 | Correct | 2 ms | 384 KB | Output is correct |
20 | Correct | 2 ms | 384 KB | Output is correct |
21 | Correct | 3 ms | 384 KB | Output is correct |
22 | Correct | 2 ms | 384 KB | Output is correct |
23 | Correct | 2 ms | 384 KB | Output is correct |
24 | Correct | 2 ms | 384 KB | Output is correct |
25 | Correct | 3 ms | 256 KB | Output is correct |
26 | Correct | 3 ms | 384 KB | Output is correct |
27 | Correct | 2 ms | 384 KB | Output is correct |
28 | Correct | 2 ms | 384 KB | Output is correct |
29 | Correct | 2 ms | 384 KB | Output is correct |
30 | Correct | 3 ms | 384 KB | Output is correct |
31 | Correct | 2 ms | 384 KB | Output is correct |
32 | Correct | 2 ms | 384 KB | Output is correct |
33 | Correct | 2 ms | 384 KB | Output is correct |
34 | Correct | 19 ms | 12288 KB | Output is correct |
35 | Correct | 11 ms | 8348 KB | Output is correct |
36 | Correct | 16 ms | 12160 KB | Output is correct |
37 | Correct | 19 ms | 12288 KB | Output is correct |
38 | Correct | 20 ms | 12288 KB | Output is correct |
39 | Correct | 19 ms | 12284 KB | Output is correct |
40 | Correct | 18 ms | 12288 KB | Output is correct |
41 | Correct | 17 ms | 12288 KB | Output is correct |
42 | Correct | 17 ms | 12288 KB | Output is correct |
43 | Correct | 17 ms | 12264 KB | Output is correct |
44 | Correct | 21 ms | 12288 KB | Output is correct |
45 | Correct | 17 ms | 12288 KB | Output is correct |
46 | Correct | 17 ms | 12160 KB | Output is correct |
47 | Correct | 24 ms | 12288 KB | Output is correct |
48 | Correct | 15 ms | 12416 KB | Output is correct |
49 | Correct | 17 ms | 12160 KB | Output is correct |
50 | Correct | 16 ms | 12288 KB | Output is correct |
51 | Correct | 16 ms | 12288 KB | Output is correct |
52 | Correct | 17 ms | 12288 KB | Output is correct |
53 | Correct | 10 ms | 8448 KB | Output is correct |
54 | Correct | 16 ms | 10368 KB | Output is correct |
55 | Correct | 7 ms | 3200 KB | Output is correct |
56 | Correct | 3 ms | 384 KB | Output is correct |
57 | Correct | 8 ms | 3584 KB | Output is correct |
58 | Correct | 16 ms | 10880 KB | Output is correct |
59 | Correct | 16 ms | 12544 KB | Output is correct |
60 | Correct | 22 ms | 12672 KB | Output is correct |
61 | Correct | 21 ms | 11264 KB | Output is correct |
62 | Correct | 16 ms | 10680 KB | Output is correct |
63 | Correct | 15 ms | 9984 KB | Output is correct |
64 | Correct | 13 ms | 7808 KB | Output is correct |
65 | Runtime error | 4 ms | 512 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
66 | Halted | 0 ms | 0 KB | - |