# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
620850 | 2022-08-03T09:45:20 Z | patrikpavic2 | Group Photo (JOI21_ho_t3) | C++17 | 979 ms | 233600 KB |
#include <cstdio> #include <algorithm> using namespace std; const int N = 5050; int n, A[N], P[N][N], inv[N][N], pos[N], dp[N], vec[N][N]; int main(){ scanf("%d", &n); for(int i = 0;i < n;i++){ scanf("%d", A + i), A[i]--; pos[A[i]] = i; } for(int i = 0;i < n;i++){ if(i){ for(int j = 0;j < n;j++) P[i][j] = P[i - 1][j]; } for(int j = A[i];j < n;j++) P[i][j]++; } for(int r = 0;r < n;r++){ inv[r][r] = 0; vec[r][r] = P[pos[r]][n - 1] - P[pos[r]][r]; for(int l = r - 1;l >= 0;l--){ inv[l][r] = inv[l + 1][r]; vec[l][r] = vec[l + 1][r]; inv[l][r] += P[pos[l]][r] - P[pos[l]][l]; vec[l][r] += P[pos[l]][n - 1] - P[pos[l]][r]; } } for(int i = 0;i < n;i++){ dp[i] = i * (i + 1) / 2 - inv[0][i] + vec[0][i]; for(int j = 0;j < i;j++){ dp[i] = min(dp[i], dp[j] + (i - j) * (i - j - 1) / 2 - inv[j + 1][i] + vec[j + 1][i]); } } printf("%d\n", dp[n - 1]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 296 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 292 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 0 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 424 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 296 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 292 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 0 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 424 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 468 KB | Output is correct |
12 | Correct | 1 ms | 468 KB | Output is correct |
13 | Correct | 1 ms | 468 KB | Output is correct |
14 | Correct | 1 ms | 468 KB | Output is correct |
15 | Correct | 0 ms | 548 KB | Output is correct |
16 | Correct | 1 ms | 552 KB | Output is correct |
17 | Correct | 1 ms | 548 KB | Output is correct |
18 | Correct | 0 ms | 548 KB | Output is correct |
19 | Correct | 0 ms | 468 KB | Output is correct |
20 | Correct | 0 ms | 468 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 296 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 292 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 0 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 424 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 468 KB | Output is correct |
12 | Correct | 1 ms | 468 KB | Output is correct |
13 | Correct | 1 ms | 468 KB | Output is correct |
14 | Correct | 1 ms | 468 KB | Output is correct |
15 | Correct | 0 ms | 548 KB | Output is correct |
16 | Correct | 1 ms | 552 KB | Output is correct |
17 | Correct | 1 ms | 548 KB | Output is correct |
18 | Correct | 0 ms | 548 KB | Output is correct |
19 | Correct | 0 ms | 468 KB | Output is correct |
20 | Correct | 0 ms | 468 KB | Output is correct |
21 | Correct | 1 ms | 2900 KB | Output is correct |
22 | Correct | 1 ms | 3028 KB | Output is correct |
23 | Correct | 2 ms | 2984 KB | Output is correct |
24 | Correct | 2 ms | 3028 KB | Output is correct |
25 | Correct | 2 ms | 2984 KB | Output is correct |
26 | Correct | 2 ms | 2984 KB | Output is correct |
27 | Correct | 2 ms | 3028 KB | Output is correct |
28 | Correct | 2 ms | 3028 KB | Output is correct |
29 | Correct | 2 ms | 2980 KB | Output is correct |
30 | Correct | 1 ms | 3028 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 296 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 292 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 0 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 424 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 468 KB | Output is correct |
12 | Correct | 1 ms | 468 KB | Output is correct |
13 | Correct | 1 ms | 468 KB | Output is correct |
14 | Correct | 1 ms | 468 KB | Output is correct |
15 | Correct | 0 ms | 548 KB | Output is correct |
16 | Correct | 1 ms | 552 KB | Output is correct |
17 | Correct | 1 ms | 548 KB | Output is correct |
18 | Correct | 0 ms | 548 KB | Output is correct |
19 | Correct | 0 ms | 468 KB | Output is correct |
20 | Correct | 0 ms | 468 KB | Output is correct |
21 | Correct | 1 ms | 2900 KB | Output is correct |
22 | Correct | 1 ms | 3028 KB | Output is correct |
23 | Correct | 2 ms | 2984 KB | Output is correct |
24 | Correct | 2 ms | 3028 KB | Output is correct |
25 | Correct | 2 ms | 2984 KB | Output is correct |
26 | Correct | 2 ms | 2984 KB | Output is correct |
27 | Correct | 2 ms | 3028 KB | Output is correct |
28 | Correct | 2 ms | 3028 KB | Output is correct |
29 | Correct | 2 ms | 2980 KB | Output is correct |
30 | Correct | 1 ms | 3028 KB | Output is correct |
31 | Correct | 17 ms | 14864 KB | Output is correct |
32 | Correct | 17 ms | 14936 KB | Output is correct |
33 | Correct | 21 ms | 14924 KB | Output is correct |
34 | Correct | 25 ms | 15020 KB | Output is correct |
35 | Correct | 20 ms | 14932 KB | Output is correct |
36 | Correct | 18 ms | 14932 KB | Output is correct |
37 | Correct | 25 ms | 14924 KB | Output is correct |
38 | Correct | 19 ms | 14924 KB | Output is correct |
39 | Correct | 24 ms | 14924 KB | Output is correct |
40 | Correct | 19 ms | 14872 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 296 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 292 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 0 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 424 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 468 KB | Output is correct |
12 | Correct | 1 ms | 468 KB | Output is correct |
13 | Correct | 1 ms | 468 KB | Output is correct |
14 | Correct | 1 ms | 468 KB | Output is correct |
15 | Correct | 0 ms | 548 KB | Output is correct |
16 | Correct | 1 ms | 552 KB | Output is correct |
17 | Correct | 1 ms | 548 KB | Output is correct |
18 | Correct | 0 ms | 548 KB | Output is correct |
19 | Correct | 0 ms | 468 KB | Output is correct |
20 | Correct | 0 ms | 468 KB | Output is correct |
21 | Correct | 1 ms | 2900 KB | Output is correct |
22 | Correct | 1 ms | 3028 KB | Output is correct |
23 | Correct | 2 ms | 2984 KB | Output is correct |
24 | Correct | 2 ms | 3028 KB | Output is correct |
25 | Correct | 2 ms | 2984 KB | Output is correct |
26 | Correct | 2 ms | 2984 KB | Output is correct |
27 | Correct | 2 ms | 3028 KB | Output is correct |
28 | Correct | 2 ms | 3028 KB | Output is correct |
29 | Correct | 2 ms | 2980 KB | Output is correct |
30 | Correct | 1 ms | 3028 KB | Output is correct |
31 | Correct | 17 ms | 14864 KB | Output is correct |
32 | Correct | 17 ms | 14936 KB | Output is correct |
33 | Correct | 21 ms | 14924 KB | Output is correct |
34 | Correct | 25 ms | 15020 KB | Output is correct |
35 | Correct | 20 ms | 14932 KB | Output is correct |
36 | Correct | 18 ms | 14932 KB | Output is correct |
37 | Correct | 25 ms | 14924 KB | Output is correct |
38 | Correct | 19 ms | 14924 KB | Output is correct |
39 | Correct | 24 ms | 14924 KB | Output is correct |
40 | Correct | 19 ms | 14872 KB | Output is correct |
41 | Correct | 889 ms | 233316 KB | Output is correct |
42 | Correct | 891 ms | 233372 KB | Output is correct |
43 | Correct | 919 ms | 233396 KB | Output is correct |
44 | Correct | 892 ms | 233420 KB | Output is correct |
45 | Correct | 979 ms | 233456 KB | Output is correct |
46 | Correct | 954 ms | 233488 KB | Output is correct |
47 | Correct | 893 ms | 233420 KB | Output is correct |
48 | Correct | 900 ms | 233496 KB | Output is correct |
49 | Correct | 898 ms | 233496 KB | Output is correct |
50 | Correct | 894 ms | 233508 KB | Output is correct |
51 | Correct | 891 ms | 233600 KB | Output is correct |
52 | Correct | 880 ms | 233592 KB | Output is correct |
53 | Correct | 910 ms | 233532 KB | Output is correct |
54 | Correct | 957 ms | 233556 KB | Output is correct |
55 | Correct | 896 ms | 233548 KB | Output is correct |