# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
50111 | 2018-06-07T14:39:21 Z | SpaimaCarpatilor | Rope (JOI17_rope) | C++17 | 385 ms | 79180 KB |
#include<bits/stdc++.h> using namespace std; int N, M, ans[5009], h[5009][5009], g[5009], a[1000009]; int main () { //sfreopen ("input", "r", stdin); //freopen ("output", "w", stdout); scanf ("%d %d", &N, &M); for (int i=1; i<=M; i++) ans[i] = N; for (int i=1; i<=N; i++) scanf ("%d", &a[i]), ans[a[i]] --; for (int shift = 0; shift < 2; shift ++) { int all = 0; for (int i=shift + 1; i<N; i+=2) { all ++; g[a[i]] ++, g[a[i + 1]] ++; if (a[i] < a[i + 1]) h[a[i]][a[i + 1]] ++; else h[a[i + 1]][a[i]] ++; } for (int i=1; i<=M; i++) for (int j=i + 1; j<=M; j++) { int curr = 2 * (all - g[i] - g[j] + h[i][j] + h[i][i] + h[j][j]) + (g[i] + g[j] - h[i][j] - 2 * h[i][i] - 2 * h[j][j]); if (shift == 1) curr += (a[1] != i && a[1] != j); if (N % 2 != shift) curr += (a[N] != i && a[N] != j); if (curr < ans[i]) ans[i] = curr; if (curr < ans[j]) ans[j] = curr; } for (int i=shift + 1; i<N; i+=2) { g[a[i]] --, g[a[i + 1]] --; if (a[i] < a[i + 1]) h[a[i]][a[i + 1]] --; else h[a[i + 1]][a[i]] --; } } for (int i=1; i<=M; i++) printf ("%d\n", ans[i]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 488 KB | Output is correct |
3 | Correct | 2 ms | 488 KB | Output is correct |
4 | Correct | 3 ms | 544 KB | Output is correct |
5 | Correct | 2 ms | 544 KB | Output is correct |
6 | Correct | 2 ms | 544 KB | Output is correct |
7 | Correct | 3 ms | 548 KB | Output is correct |
8 | Correct | 3 ms | 548 KB | Output is correct |
9 | Correct | 2 ms | 548 KB | Output is correct |
10 | Correct | 3 ms | 548 KB | Output is correct |
11 | Correct | 3 ms | 548 KB | Output is correct |
12 | Correct | 4 ms | 676 KB | Output is correct |
13 | Correct | 3 ms | 676 KB | Output is correct |
14 | Correct | 3 ms | 676 KB | Output is correct |
15 | Correct | 3 ms | 676 KB | Output is correct |
16 | Correct | 3 ms | 676 KB | Output is correct |
17 | Correct | 3 ms | 676 KB | Output is correct |
18 | Correct | 3 ms | 676 KB | Output is correct |
19 | Correct | 3 ms | 676 KB | Output is correct |
20 | Correct | 2 ms | 676 KB | Output is correct |
21 | Correct | 3 ms | 676 KB | Output is correct |
22 | Correct | 2 ms | 676 KB | Output is correct |
23 | Correct | 2 ms | 676 KB | Output is correct |
24 | Correct | 3 ms | 676 KB | Output is correct |
25 | Correct | 2 ms | 676 KB | Output is correct |
26 | Correct | 2 ms | 676 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 488 KB | Output is correct |
3 | Correct | 2 ms | 488 KB | Output is correct |
4 | Correct | 3 ms | 544 KB | Output is correct |
5 | Correct | 2 ms | 544 KB | Output is correct |
6 | Correct | 2 ms | 544 KB | Output is correct |
7 | Correct | 3 ms | 548 KB | Output is correct |
8 | Correct | 3 ms | 548 KB | Output is correct |
9 | Correct | 2 ms | 548 KB | Output is correct |
10 | Correct | 3 ms | 548 KB | Output is correct |
11 | Correct | 3 ms | 548 KB | Output is correct |
12 | Correct | 4 ms | 676 KB | Output is correct |
13 | Correct | 3 ms | 676 KB | Output is correct |
14 | Correct | 3 ms | 676 KB | Output is correct |
15 | Correct | 3 ms | 676 KB | Output is correct |
16 | Correct | 3 ms | 676 KB | Output is correct |
17 | Correct | 3 ms | 676 KB | Output is correct |
18 | Correct | 3 ms | 676 KB | Output is correct |
19 | Correct | 3 ms | 676 KB | Output is correct |
20 | Correct | 2 ms | 676 KB | Output is correct |
21 | Correct | 3 ms | 676 KB | Output is correct |
22 | Correct | 2 ms | 676 KB | Output is correct |
23 | Correct | 2 ms | 676 KB | Output is correct |
24 | Correct | 3 ms | 676 KB | Output is correct |
25 | Correct | 2 ms | 676 KB | Output is correct |
26 | Correct | 2 ms | 676 KB | Output is correct |
27 | Correct | 16 ms | 1136 KB | Output is correct |
28 | Correct | 19 ms | 1452 KB | Output is correct |
29 | Correct | 18 ms | 1808 KB | Output is correct |
30 | Correct | 18 ms | 2004 KB | Output is correct |
31 | Correct | 19 ms | 2264 KB | Output is correct |
32 | Correct | 17 ms | 2264 KB | Output is correct |
33 | Correct | 18 ms | 2556 KB | Output is correct |
34 | Correct | 18 ms | 2640 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 488 KB | Output is correct |
3 | Correct | 2 ms | 488 KB | Output is correct |
4 | Correct | 3 ms | 544 KB | Output is correct |
5 | Correct | 2 ms | 544 KB | Output is correct |
6 | Correct | 2 ms | 544 KB | Output is correct |
7 | Correct | 3 ms | 548 KB | Output is correct |
8 | Correct | 3 ms | 548 KB | Output is correct |
9 | Correct | 2 ms | 548 KB | Output is correct |
10 | Correct | 3 ms | 548 KB | Output is correct |
11 | Correct | 3 ms | 548 KB | Output is correct |
12 | Correct | 4 ms | 676 KB | Output is correct |
13 | Correct | 3 ms | 676 KB | Output is correct |
14 | Correct | 3 ms | 676 KB | Output is correct |
15 | Correct | 3 ms | 676 KB | Output is correct |
16 | Correct | 3 ms | 676 KB | Output is correct |
17 | Correct | 3 ms | 676 KB | Output is correct |
18 | Correct | 3 ms | 676 KB | Output is correct |
19 | Correct | 3 ms | 676 KB | Output is correct |
20 | Correct | 2 ms | 676 KB | Output is correct |
21 | Correct | 3 ms | 676 KB | Output is correct |
22 | Correct | 2 ms | 676 KB | Output is correct |
23 | Correct | 2 ms | 676 KB | Output is correct |
24 | Correct | 3 ms | 676 KB | Output is correct |
25 | Correct | 2 ms | 676 KB | Output is correct |
26 | Correct | 2 ms | 676 KB | Output is correct |
27 | Correct | 16 ms | 1136 KB | Output is correct |
28 | Correct | 19 ms | 1452 KB | Output is correct |
29 | Correct | 18 ms | 1808 KB | Output is correct |
30 | Correct | 18 ms | 2004 KB | Output is correct |
31 | Correct | 19 ms | 2264 KB | Output is correct |
32 | Correct | 17 ms | 2264 KB | Output is correct |
33 | Correct | 18 ms | 2556 KB | Output is correct |
34 | Correct | 18 ms | 2640 KB | Output is correct |
35 | Correct | 24 ms | 5524 KB | Output is correct |
36 | Correct | 23 ms | 5896 KB | Output is correct |
37 | Correct | 35 ms | 6172 KB | Output is correct |
38 | Correct | 24 ms | 6584 KB | Output is correct |
39 | Correct | 23 ms | 7044 KB | Output is correct |
40 | Correct | 24 ms | 7416 KB | Output is correct |
41 | Correct | 23 ms | 7852 KB | Output is correct |
42 | Correct | 20 ms | 7852 KB | Output is correct |
43 | Correct | 21 ms | 7852 KB | Output is correct |
44 | Correct | 23 ms | 8896 KB | Output is correct |
45 | Correct | 21 ms | 9264 KB | Output is correct |
46 | Correct | 20 ms | 9264 KB | Output is correct |
47 | Correct | 22 ms | 9264 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 488 KB | Output is correct |
3 | Correct | 2 ms | 488 KB | Output is correct |
4 | Correct | 3 ms | 544 KB | Output is correct |
5 | Correct | 2 ms | 544 KB | Output is correct |
6 | Correct | 2 ms | 544 KB | Output is correct |
7 | Correct | 3 ms | 548 KB | Output is correct |
8 | Correct | 3 ms | 548 KB | Output is correct |
9 | Correct | 2 ms | 548 KB | Output is correct |
10 | Correct | 3 ms | 548 KB | Output is correct |
11 | Correct | 3 ms | 548 KB | Output is correct |
12 | Correct | 4 ms | 676 KB | Output is correct |
13 | Correct | 3 ms | 676 KB | Output is correct |
14 | Correct | 3 ms | 676 KB | Output is correct |
15 | Correct | 3 ms | 676 KB | Output is correct |
16 | Correct | 3 ms | 676 KB | Output is correct |
17 | Correct | 3 ms | 676 KB | Output is correct |
18 | Correct | 3 ms | 676 KB | Output is correct |
19 | Correct | 3 ms | 676 KB | Output is correct |
20 | Correct | 2 ms | 676 KB | Output is correct |
21 | Correct | 3 ms | 676 KB | Output is correct |
22 | Correct | 2 ms | 676 KB | Output is correct |
23 | Correct | 2 ms | 676 KB | Output is correct |
24 | Correct | 3 ms | 676 KB | Output is correct |
25 | Correct | 2 ms | 676 KB | Output is correct |
26 | Correct | 2 ms | 676 KB | Output is correct |
27 | Correct | 16 ms | 1136 KB | Output is correct |
28 | Correct | 19 ms | 1452 KB | Output is correct |
29 | Correct | 18 ms | 1808 KB | Output is correct |
30 | Correct | 18 ms | 2004 KB | Output is correct |
31 | Correct | 19 ms | 2264 KB | Output is correct |
32 | Correct | 17 ms | 2264 KB | Output is correct |
33 | Correct | 18 ms | 2556 KB | Output is correct |
34 | Correct | 18 ms | 2640 KB | Output is correct |
35 | Correct | 24 ms | 5524 KB | Output is correct |
36 | Correct | 23 ms | 5896 KB | Output is correct |
37 | Correct | 35 ms | 6172 KB | Output is correct |
38 | Correct | 24 ms | 6584 KB | Output is correct |
39 | Correct | 23 ms | 7044 KB | Output is correct |
40 | Correct | 24 ms | 7416 KB | Output is correct |
41 | Correct | 23 ms | 7852 KB | Output is correct |
42 | Correct | 20 ms | 7852 KB | Output is correct |
43 | Correct | 21 ms | 7852 KB | Output is correct |
44 | Correct | 23 ms | 8896 KB | Output is correct |
45 | Correct | 21 ms | 9264 KB | Output is correct |
46 | Correct | 20 ms | 9264 KB | Output is correct |
47 | Correct | 22 ms | 9264 KB | Output is correct |
48 | Correct | 385 ms | 45300 KB | Output is correct |
49 | Correct | 350 ms | 49724 KB | Output is correct |
50 | Correct | 311 ms | 54124 KB | Output is correct |
51 | Correct | 207 ms | 54124 KB | Output is correct |
52 | Correct | 197 ms | 54124 KB | Output is correct |
53 | Correct | 354 ms | 66616 KB | Output is correct |
54 | Correct | 303 ms | 70768 KB | Output is correct |
55 | Correct | 259 ms | 75184 KB | Output is correct |
56 | Correct | 238 ms | 79180 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 488 KB | Output is correct |
3 | Correct | 2 ms | 488 KB | Output is correct |
4 | Correct | 3 ms | 544 KB | Output is correct |
5 | Correct | 2 ms | 544 KB | Output is correct |
6 | Correct | 2 ms | 544 KB | Output is correct |
7 | Correct | 3 ms | 548 KB | Output is correct |
8 | Correct | 3 ms | 548 KB | Output is correct |
9 | Correct | 2 ms | 548 KB | Output is correct |
10 | Correct | 3 ms | 548 KB | Output is correct |
11 | Correct | 3 ms | 548 KB | Output is correct |
12 | Correct | 4 ms | 676 KB | Output is correct |
13 | Correct | 3 ms | 676 KB | Output is correct |
14 | Correct | 3 ms | 676 KB | Output is correct |
15 | Correct | 3 ms | 676 KB | Output is correct |
16 | Correct | 3 ms | 676 KB | Output is correct |
17 | Correct | 3 ms | 676 KB | Output is correct |
18 | Correct | 3 ms | 676 KB | Output is correct |
19 | Correct | 3 ms | 676 KB | Output is correct |
20 | Correct | 2 ms | 676 KB | Output is correct |
21 | Correct | 3 ms | 676 KB | Output is correct |
22 | Correct | 2 ms | 676 KB | Output is correct |
23 | Correct | 2 ms | 676 KB | Output is correct |
24 | Correct | 3 ms | 676 KB | Output is correct |
25 | Correct | 2 ms | 676 KB | Output is correct |
26 | Correct | 2 ms | 676 KB | Output is correct |
27 | Correct | 16 ms | 1136 KB | Output is correct |
28 | Correct | 19 ms | 1452 KB | Output is correct |
29 | Correct | 18 ms | 1808 KB | Output is correct |
30 | Correct | 18 ms | 2004 KB | Output is correct |
31 | Correct | 19 ms | 2264 KB | Output is correct |
32 | Correct | 17 ms | 2264 KB | Output is correct |
33 | Correct | 18 ms | 2556 KB | Output is correct |
34 | Correct | 18 ms | 2640 KB | Output is correct |
35 | Correct | 24 ms | 5524 KB | Output is correct |
36 | Correct | 23 ms | 5896 KB | Output is correct |
37 | Correct | 35 ms | 6172 KB | Output is correct |
38 | Correct | 24 ms | 6584 KB | Output is correct |
39 | Correct | 23 ms | 7044 KB | Output is correct |
40 | Correct | 24 ms | 7416 KB | Output is correct |
41 | Correct | 23 ms | 7852 KB | Output is correct |
42 | Correct | 20 ms | 7852 KB | Output is correct |
43 | Correct | 21 ms | 7852 KB | Output is correct |
44 | Correct | 23 ms | 8896 KB | Output is correct |
45 | Correct | 21 ms | 9264 KB | Output is correct |
46 | Correct | 20 ms | 9264 KB | Output is correct |
47 | Correct | 22 ms | 9264 KB | Output is correct |
48 | Correct | 385 ms | 45300 KB | Output is correct |
49 | Correct | 350 ms | 49724 KB | Output is correct |
50 | Correct | 311 ms | 54124 KB | Output is correct |
51 | Correct | 207 ms | 54124 KB | Output is correct |
52 | Correct | 197 ms | 54124 KB | Output is correct |
53 | Correct | 354 ms | 66616 KB | Output is correct |
54 | Correct | 303 ms | 70768 KB | Output is correct |
55 | Correct | 259 ms | 75184 KB | Output is correct |
56 | Correct | 238 ms | 79180 KB | Output is correct |
57 | Runtime error | 6 ms | 79180 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
58 | Halted | 0 ms | 0 KB | - |