#include <stdio.h>
#include <string.h>
#define N 5000
int min(int a, int b) { return a < b ? a : b; }
int main() {
static int aa[N], cc[N + 1][N + 1], dp[N + 1];
int n, i, j, a, b, cnt;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]), aa[i]--;
cnt = 0;
for (i = 0; i < n; i++)
for (j = i + 1; j < n; j++)
if (aa[i] < aa[j])
cc[aa[i]][aa[j] + 1]++;
else
cc[aa[j]][aa[i] + 1]--, cnt++;
for (a = n; a >= 0; a--)
for (b = a + 1; b <= n; b++)
cc[a][b] += cc[a + 1][b];
for (a = n; a >= 0; a--)
for (b = a + 1; b <= n; b++)
cc[a][b] += cc[a][b - 1];
memset(dp, 0x3f, (n + 1) * sizeof *dp), dp[0] = cnt;
for (a = 0; a < n; a++)
for (b = a + 1; b <= n; b++)
dp[b] = min(dp[b], dp[a] + cc[a][b]);
printf("%d\n", dp[n]);
return 0;
}
Compilation message
Main.c: In function 'main':
Main.c:12:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
Main.c:14:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%d", &aa[i]), aa[i]--;
| ^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
288 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
288 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
1060 KB |
Output is correct |
22 |
Correct |
1 ms |
1192 KB |
Output is correct |
23 |
Correct |
1 ms |
1108 KB |
Output is correct |
24 |
Correct |
1 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1236 KB |
Output is correct |
26 |
Correct |
1 ms |
1108 KB |
Output is correct |
27 |
Correct |
1 ms |
1192 KB |
Output is correct |
28 |
Correct |
1 ms |
1188 KB |
Output is correct |
29 |
Correct |
1 ms |
1108 KB |
Output is correct |
30 |
Correct |
1 ms |
1192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
288 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
1060 KB |
Output is correct |
22 |
Correct |
1 ms |
1192 KB |
Output is correct |
23 |
Correct |
1 ms |
1108 KB |
Output is correct |
24 |
Correct |
1 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1236 KB |
Output is correct |
26 |
Correct |
1 ms |
1108 KB |
Output is correct |
27 |
Correct |
1 ms |
1192 KB |
Output is correct |
28 |
Correct |
1 ms |
1188 KB |
Output is correct |
29 |
Correct |
1 ms |
1108 KB |
Output is correct |
30 |
Correct |
1 ms |
1192 KB |
Output is correct |
31 |
Correct |
5 ms |
4692 KB |
Output is correct |
32 |
Correct |
5 ms |
4692 KB |
Output is correct |
33 |
Correct |
5 ms |
4692 KB |
Output is correct |
34 |
Correct |
5 ms |
4692 KB |
Output is correct |
35 |
Correct |
5 ms |
4692 KB |
Output is correct |
36 |
Correct |
5 ms |
4692 KB |
Output is correct |
37 |
Correct |
6 ms |
4692 KB |
Output is correct |
38 |
Correct |
6 ms |
4776 KB |
Output is correct |
39 |
Correct |
5 ms |
4692 KB |
Output is correct |
40 |
Correct |
6 ms |
4692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
288 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
1060 KB |
Output is correct |
22 |
Correct |
1 ms |
1192 KB |
Output is correct |
23 |
Correct |
1 ms |
1108 KB |
Output is correct |
24 |
Correct |
1 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1236 KB |
Output is correct |
26 |
Correct |
1 ms |
1108 KB |
Output is correct |
27 |
Correct |
1 ms |
1192 KB |
Output is correct |
28 |
Correct |
1 ms |
1188 KB |
Output is correct |
29 |
Correct |
1 ms |
1108 KB |
Output is correct |
30 |
Correct |
1 ms |
1192 KB |
Output is correct |
31 |
Correct |
5 ms |
4692 KB |
Output is correct |
32 |
Correct |
5 ms |
4692 KB |
Output is correct |
33 |
Correct |
5 ms |
4692 KB |
Output is correct |
34 |
Correct |
5 ms |
4692 KB |
Output is correct |
35 |
Correct |
5 ms |
4692 KB |
Output is correct |
36 |
Correct |
5 ms |
4692 KB |
Output is correct |
37 |
Correct |
6 ms |
4692 KB |
Output is correct |
38 |
Correct |
6 ms |
4776 KB |
Output is correct |
39 |
Correct |
5 ms |
4692 KB |
Output is correct |
40 |
Correct |
6 ms |
4692 KB |
Output is correct |
41 |
Correct |
189 ms |
67240 KB |
Output is correct |
42 |
Correct |
181 ms |
67212 KB |
Output is correct |
43 |
Correct |
197 ms |
67196 KB |
Output is correct |
44 |
Correct |
199 ms |
67352 KB |
Output is correct |
45 |
Correct |
180 ms |
67204 KB |
Output is correct |
46 |
Correct |
187 ms |
67408 KB |
Output is correct |
47 |
Correct |
187 ms |
67232 KB |
Output is correct |
48 |
Correct |
184 ms |
67292 KB |
Output is correct |
49 |
Correct |
185 ms |
67288 KB |
Output is correct |
50 |
Correct |
181 ms |
67300 KB |
Output is correct |
51 |
Correct |
188 ms |
67260 KB |
Output is correct |
52 |
Correct |
196 ms |
67256 KB |
Output is correct |
53 |
Correct |
191 ms |
67276 KB |
Output is correct |
54 |
Correct |
182 ms |
67260 KB |
Output is correct |
55 |
Correct |
185 ms |
67300 KB |
Output is correct |