| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 500635 | rainboy | Tortoise (CEOI21_tortoise) | C11 | 25 ms | 1292 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 + 1], tt[N][N];
int n, i, j, k, 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; 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 + 1) * sizeof *dp[i]);
ans = 0;
for (i = 0; i < n; i++)
if (aa[i] > 0) {
dp[i][1] = i;
for (k = n * 2; k >= 0; k--) {
int t = dp[i][k];
if (t > i * 2)
continue;
for (k_ = k + 1; k_ <= n * 2 && k_ - k < aa[i]; k_++)
dp[i][k_] = min(dp[i][k_], t + tt[i][i] * (k_ - k));
}
for (k = 0; k <= n * 2; 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] > 0)
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 (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
