# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
206505 | 2020-03-03T13:45:16 Z | luciocf | Holding (COCI20_holding) | C++14 | 5 ms | 632 KB |
#include <bits/stdc++.h> using namespace std; const int maxn = 110; const int maxk = 2505; const int inf = 1e9+10; int a[maxn]; int dp1[maxn][maxn][maxk], dp2[maxn][maxn][maxk]; int main(void) { int n, l, r, k; scanf("%d %d %d %d", &n, &l, &r, &k); k = min(k, maxk-1); int soma = 0; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); if (i >= l && i <= r) soma += a[i]; } for (int i = 0; i <= l; i++) for (int j = l-1; j <= r; j++) for (int x = 0; x <= k; x++) dp1[i][j][x] = inf; dp1[0][l-1][0] = dp1[0][l][0] = dp1[1][l-1][0] = soma; for (int i = 1; i < l; i++) { for (int j = l; j <= r; j++) { for (int x = k; x >= 0; x--) { dp1[i][j][x] = min(dp1[i][j-1][x], dp1[i-1][j][x]); if (x-(j-i) >= 0) dp1[i][j][x] = min(dp1[i][j][x], a[i]-a[j]+dp1[i-1][j-1][x-(j-i)]); } } } for (int i = l; i <= r+1; i++) for (int j = r+1; j <= n+1; j++) for (int x = 0; x <= k; x++) dp2[i][j][x] = inf; dp2[r+1][n+1][0] = dp2[r+1][n][0] = dp2[r][n+1][0] = soma; for (int i = r; i >= l; i--) { for (int j = n; j > r; j--) { for (int x = k; x >= 0; x--) { dp2[i][j][x] = min(dp2[i+1][j][x], dp2[i][j+1][x]); if (x-(j-i) >= 0) dp2[i][j][x] = min(dp2[i][j][x], a[j]-a[i]+dp2[i+1][j+1][x-(j-i)]); } } } int ans = inf; for (int x = 0; x <= k; x++) ans = min(ans, dp2[l][r+1][x]); for (int x = 0; x <= k; x++) ans = min(ans, dp1[l-1][r][x]); for (int i = l; i <= r; i++) for (int x = 0; x <= k; x++) ans = min(ans, dp1[l-1][i][x] + dp2[i+1][r+1][k-x]); printf("%d\n", ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Incorrect | 5 ms | 632 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Incorrect | 5 ms | 632 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Incorrect | 5 ms | 632 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Incorrect | 5 ms | 632 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |