# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
199577 | 2020-02-02T05:08:36 Z | SamAnd | Holding (COCI20_holding) | C++17 | 102 ms | 106360 KB |
#include <bits/stdc++.h> using namespace std; const int N = 102; const int INF = 1000000009; int n, l, r, kk; int a[N]; int dp[N][N][N * N / 4]; int main() { scanf("%d%d%d%d", &n, &l, &r, &kk); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); kk = min(kk, (N * N / 4) - 1); int s = 0; for (int i = l; i <= r; ++i) s += a[i]; for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) for (int k = 0; k < N * N / 4; ++k) dp[i][j][k] = INF; dp[0][l - 1][0] = 0; for (int i = 0; i <= l - 1; ++i) { for (int j = l - 1; j <= r; ++j) { for (int k = 0; k <= kk; ++k) { if (k + 1 <= kk) dp[i][j][k + 1] = min(dp[i][j][k + 1], dp[i][j][k]); if (i != l - 1) dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]); if (j != r) dp[i][j + 1][k] = min(dp[i][j + 1][k], dp[i][j][k] + a[j + 1]); if (i != l - 1 && j != r && k + abs(i + 1 - (j + 1)) <= kk) dp[i + 1][j + 1][k + abs(i + 1 - (j + 1))] = min(dp[i + 1][j + 1][k + abs(i + 1 - (j + 1))], dp[i][j][k] + a[i + 1]); } } } dp[n + 1][r + 1][0] = 0; for (int i = n + 1; i >= r + 1; --i) { for (int j = r + 1; j >= l; --j) { for (int k = 0; k <= kk; ++k) { if (k + 1 <= kk) dp[i][j][k + 1] = min(dp[i][j][k + 1], dp[i][j][k]); if (i != r + 1) dp[i - 1][j][k] = min(dp[i - 1][j][k], dp[i][j][k]); if (j != l) dp[i][j - 1][k] = min(dp[i][j - 1][k], dp[i][j][k] + a[j - 1]); if (i != r + 1 && j != l && k + abs(i - 1 - (j - 1)) <= kk) dp[i - 1][j - 1][k + abs(i - 1 - (j - 1))] = min(dp[i - 1][j - 1][k + abs(i - 1 - (j - 1))], dp[i][j][k] + a[i - 1]); } } } int ans = s; for (int i = l - 1; i <= r; ++i) { for (int k = 0; k <= kk; ++k) { ans = min(ans, dp[l - 1][i][k] + dp[r + 1][i + 1][kk - k]); } } printf("%d\n", ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 70 ms | 106360 KB | Output is correct |
2 | Correct | 78 ms | 106232 KB | Output is correct |
3 | Correct | 72 ms | 106232 KB | Output is correct |
4 | Correct | 69 ms | 106360 KB | Output is correct |
5 | Correct | 75 ms | 106232 KB | Output is correct |
6 | Correct | 72 ms | 106232 KB | Output is correct |
7 | Correct | 69 ms | 106232 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 70 ms | 106360 KB | Output is correct |
2 | Correct | 78 ms | 106232 KB | Output is correct |
3 | Correct | 72 ms | 106232 KB | Output is correct |
4 | Correct | 69 ms | 106360 KB | Output is correct |
5 | Correct | 75 ms | 106232 KB | Output is correct |
6 | Correct | 72 ms | 106232 KB | Output is correct |
7 | Correct | 69 ms | 106232 KB | Output is correct |
8 | Correct | 71 ms | 106232 KB | Output is correct |
9 | Correct | 76 ms | 106164 KB | Output is correct |
10 | Correct | 79 ms | 106232 KB | Output is correct |
11 | Correct | 71 ms | 106232 KB | Output is correct |
12 | Correct | 70 ms | 106232 KB | Output is correct |
13 | Correct | 81 ms | 106232 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 70 ms | 106360 KB | Output is correct |
2 | Correct | 78 ms | 106232 KB | Output is correct |
3 | Correct | 72 ms | 106232 KB | Output is correct |
4 | Correct | 69 ms | 106360 KB | Output is correct |
5 | Correct | 75 ms | 106232 KB | Output is correct |
6 | Correct | 72 ms | 106232 KB | Output is correct |
7 | Correct | 69 ms | 106232 KB | Output is correct |
8 | Correct | 71 ms | 106232 KB | Output is correct |
9 | Correct | 76 ms | 106164 KB | Output is correct |
10 | Correct | 79 ms | 106232 KB | Output is correct |
11 | Correct | 71 ms | 106232 KB | Output is correct |
12 | Correct | 70 ms | 106232 KB | Output is correct |
13 | Correct | 81 ms | 106232 KB | Output is correct |
14 | Correct | 67 ms | 106228 KB | Output is correct |
15 | Correct | 68 ms | 106232 KB | Output is correct |
16 | Correct | 71 ms | 106360 KB | Output is correct |
17 | Correct | 69 ms | 106232 KB | Output is correct |
18 | Correct | 71 ms | 106232 KB | Output is correct |
19 | Correct | 76 ms | 106232 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 70 ms | 106360 KB | Output is correct |
2 | Correct | 78 ms | 106232 KB | Output is correct |
3 | Correct | 72 ms | 106232 KB | Output is correct |
4 | Correct | 69 ms | 106360 KB | Output is correct |
5 | Correct | 75 ms | 106232 KB | Output is correct |
6 | Correct | 72 ms | 106232 KB | Output is correct |
7 | Correct | 69 ms | 106232 KB | Output is correct |
8 | Correct | 71 ms | 106232 KB | Output is correct |
9 | Correct | 76 ms | 106164 KB | Output is correct |
10 | Correct | 79 ms | 106232 KB | Output is correct |
11 | Correct | 71 ms | 106232 KB | Output is correct |
12 | Correct | 70 ms | 106232 KB | Output is correct |
13 | Correct | 81 ms | 106232 KB | Output is correct |
14 | Correct | 67 ms | 106228 KB | Output is correct |
15 | Correct | 68 ms | 106232 KB | Output is correct |
16 | Correct | 71 ms | 106360 KB | Output is correct |
17 | Correct | 69 ms | 106232 KB | Output is correct |
18 | Correct | 71 ms | 106232 KB | Output is correct |
19 | Correct | 76 ms | 106232 KB | Output is correct |
20 | Correct | 73 ms | 106232 KB | Output is correct |
21 | Correct | 73 ms | 106304 KB | Output is correct |
22 | Correct | 70 ms | 106244 KB | Output is correct |
23 | Correct | 71 ms | 106360 KB | Output is correct |
24 | Correct | 74 ms | 106232 KB | Output is correct |
25 | Correct | 102 ms | 106232 KB | Output is correct |