#include <stdio.h>
#include <string.h>
#define N 302
#define A 200
#define INF 0x3f3f3f3f
int min(int a, int b) { return a < b ? a : b; }
int main() {
static int aa[N], dp[A + 1][A + 1], dq[A + 1][A + 1];
int n, i, a, b;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
n += 2;
for (a = 0; a <= A; a++)
memset(dp[a], 0x3f, (A + 1) * sizeof *dp[a]);
dp[0][0] = 0;
for (i = 0; i < n; i++) {
for (a = 0; a <= A; a++)
memset(dq[a], 0x3f, (A + 1) * sizeof *dq[a]);
for (a = 0; a <= A; a++)
for (b = 0; b <= A; b++) {
int x = dp[a][b];
if (x == INF || b < a || aa[i] < a)
continue;
dq[b - a][aa[i] - a] = min(dq[b - a][aa[i] - a], x + a * 7);
}
for (a = A; a >= 0; a--)
for (b = A; b >= 0; b--) {
int x = dq[a][b];
if (x == INF)
continue;
if (b > 0) {
dq[a][b - 1] = min(dq[a][b - 1], dq[a][b] + 3);
if (a > 0)
dq[a - 1][b - 1] = min(dq[a - 1][b - 1], dq[a][b] + 5);
}
}
for (a = 0; a <= A; a++)
memcpy(dp[a], dq[a], (A + 1) * sizeof *dp[a]);
}
printf("%d\n", dp[0][0]);
return 0;
}
Compilation message
skyline.c: In function 'main':
skyline.c:14:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
skyline.c:16:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
548 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
544 KB |
Output is correct |
4 |
Correct |
7 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
4 ms |
548 KB |
Output is correct |
11 |
Correct |
19 ms |
600 KB |
Output is correct |
12 |
Correct |
5 ms |
596 KB |
Output is correct |
13 |
Correct |
22 ms |
596 KB |
Output is correct |
14 |
Correct |
29 ms |
596 KB |
Output is correct |
15 |
Correct |
62 ms |
552 KB |
Output is correct |
16 |
Correct |
60 ms |
584 KB |
Output is correct |
17 |
Correct |
81 ms |
596 KB |
Output is correct |
18 |
Correct |
80 ms |
596 KB |
Output is correct |
19 |
Correct |
75 ms |
596 KB |
Output is correct |
20 |
Correct |
83 ms |
584 KB |
Output is correct |