#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 * 2];
static int tt[N][N];
int n, i, j, k, t;
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], -1, n * 2 * sizeof *dp[i]);
ans = 0;
for (i = 0; i < n; i++)
if (aa[i] == 1) {
dp[i][0] = max(dp[i][0], 1);
for (t = 0; t <= i * 2; t++) {
int x = dp[i][t];
if (x == -1)
continue;
ans = max(ans, x);
for (j = i + 1; j < n; j++)
if (aa[j] == 1) {
int t_ = t + tt[i][j];
if (t_ <= j * 2)
dp[j][t_] = max(dp[j][t_], dp[i][t] + 1);
}
}
}
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]);
| ^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
268 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
268 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
268 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
268 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
268 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |