#include <stdio.h>
#include <string.h>
#define N 300
#define INF 0x3f3f3f3f
int abs_(int a) { return a > 0 ? a : -a; }
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
int main() {
static int aa[N], dp[N][N + 1];
static int tt[N][N];
int n, i, j, k;
long long ans;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
for (i = 0; i < n; i++)
for (j = i + 1; j < n; j++)
if (aa[i] != -1 && aa[j] != -1) {
tt[i][j] = INF;
for (k = 0; k < n; k++)
if (aa[k] == -1)
tt[i][j] = min(tt[i][j], abs_(i - k) + abs_(k - j));
}
for (i = 0; i < n; i++)
memset(dp[i], 0x3f, n * 2 * sizeof *dp[i]);
ans = 0;
for (i = 0; i < n; i++)
if (aa[i] == 1) {
dp[i][1] = i;
for (k = 0; k <= n; k++) {
int t = dp[i][k];
if (t > i * 2)
continue;
ans = max(ans, k);
for (j = i + 1; j < n; j++)
if (aa[j] == 1)
dp[j][k + 1] = min(dp[j][k + 1], t + tt[i][j]);
}
}
ans = -ans;
for (i = 0; i < n; i++)
if (aa[i] > 0)
ans += aa[i];
printf("%lld\n", ans);
return 0;
}
Compilation message
tortoise.c: In function 'main':
tortoise.c:17:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
tortoise.c:19:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
248 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
248 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
13 ms |
856 KB |
Output is correct |
28 |
Correct |
21 ms |
888 KB |
Output is correct |
29 |
Correct |
19 ms |
856 KB |
Output is correct |
30 |
Correct |
10 ms |
844 KB |
Output is correct |
31 |
Correct |
17 ms |
932 KB |
Output is correct |
32 |
Correct |
6 ms |
716 KB |
Output is correct |
33 |
Correct |
13 ms |
844 KB |
Output is correct |
34 |
Correct |
10 ms |
764 KB |
Output is correct |
35 |
Correct |
15 ms |
864 KB |
Output is correct |
36 |
Correct |
15 ms |
972 KB |
Output is correct |
37 |
Correct |
15 ms |
916 KB |
Output is correct |
38 |
Correct |
14 ms |
972 KB |
Output is correct |
39 |
Correct |
14 ms |
896 KB |
Output is correct |
40 |
Correct |
15 ms |
972 KB |
Output is correct |
41 |
Correct |
13 ms |
908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
248 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
13 ms |
856 KB |
Output is correct |
28 |
Correct |
21 ms |
888 KB |
Output is correct |
29 |
Correct |
19 ms |
856 KB |
Output is correct |
30 |
Correct |
10 ms |
844 KB |
Output is correct |
31 |
Correct |
17 ms |
932 KB |
Output is correct |
32 |
Correct |
6 ms |
716 KB |
Output is correct |
33 |
Correct |
13 ms |
844 KB |
Output is correct |
34 |
Correct |
10 ms |
764 KB |
Output is correct |
35 |
Correct |
15 ms |
864 KB |
Output is correct |
36 |
Correct |
15 ms |
972 KB |
Output is correct |
37 |
Correct |
15 ms |
916 KB |
Output is correct |
38 |
Correct |
14 ms |
972 KB |
Output is correct |
39 |
Correct |
14 ms |
896 KB |
Output is correct |
40 |
Correct |
15 ms |
972 KB |
Output is correct |
41 |
Correct |
13 ms |
908 KB |
Output is correct |
42 |
Incorrect |
4 ms |
716 KB |
Output isn't correct |
43 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
248 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
13 ms |
856 KB |
Output is correct |
28 |
Correct |
21 ms |
888 KB |
Output is correct |
29 |
Correct |
19 ms |
856 KB |
Output is correct |
30 |
Correct |
10 ms |
844 KB |
Output is correct |
31 |
Correct |
17 ms |
932 KB |
Output is correct |
32 |
Correct |
6 ms |
716 KB |
Output is correct |
33 |
Correct |
13 ms |
844 KB |
Output is correct |
34 |
Correct |
10 ms |
764 KB |
Output is correct |
35 |
Correct |
15 ms |
864 KB |
Output is correct |
36 |
Correct |
15 ms |
972 KB |
Output is correct |
37 |
Correct |
15 ms |
916 KB |
Output is correct |
38 |
Correct |
14 ms |
972 KB |
Output is correct |
39 |
Correct |
14 ms |
896 KB |
Output is correct |
40 |
Correct |
15 ms |
972 KB |
Output is correct |
41 |
Correct |
13 ms |
908 KB |
Output is correct |
42 |
Incorrect |
4 ms |
716 KB |
Output isn't correct |
43 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
248 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
13 ms |
856 KB |
Output is correct |
28 |
Correct |
21 ms |
888 KB |
Output is correct |
29 |
Correct |
19 ms |
856 KB |
Output is correct |
30 |
Correct |
10 ms |
844 KB |
Output is correct |
31 |
Correct |
17 ms |
932 KB |
Output is correct |
32 |
Correct |
6 ms |
716 KB |
Output is correct |
33 |
Correct |
13 ms |
844 KB |
Output is correct |
34 |
Correct |
10 ms |
764 KB |
Output is correct |
35 |
Correct |
15 ms |
864 KB |
Output is correct |
36 |
Correct |
15 ms |
972 KB |
Output is correct |
37 |
Correct |
15 ms |
916 KB |
Output is correct |
38 |
Correct |
14 ms |
972 KB |
Output is correct |
39 |
Correct |
14 ms |
896 KB |
Output is correct |
40 |
Correct |
15 ms |
972 KB |
Output is correct |
41 |
Correct |
13 ms |
908 KB |
Output is correct |
42 |
Incorrect |
4 ms |
716 KB |
Output isn't correct |
43 |
Halted |
0 ms |
0 KB |
- |