# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
841349 | 2023-09-01T14:23:30 Z | alex_2008 | K개의 묶음 (IZhO14_blocks) | C++14 | 1 ms | 312 KB |
#define _CRT_SECURE_NO_WARNINGS #include <iostream> using namespace std; const int N = 100100, K = 101; int dp[N][K], a[N], prevv[N], mn[N]; int main() { int n, k; scanf("%d%d", &n, &k); a[0] = 1e6 + 10; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); int j = i - 1; while (a[j] < a[i]) { j = prevv[j]; } prevv[i] = j; } dp[1][0] = 1e9 + 10; for (int i = 1; i <= n; i++) { dp[i][1] = max(dp[i - 1][1], a[i]); } for (int j = 2; j <= k; j++) { for (int i = 1; i <= n; i++) { mn[i] = 1e9 + 10; int x = i - 1; while (x != prevv[i]) { mn[i] = min(mn[i], mn[x]); x = prevv[x]; } mn[i] = min(mn[i], dp[i][j - 1]); } for (int i = 0; i <= n; i++) { if (i < j) dp[i][j] = 1e9; else { dp[i][j] = dp[prevv[i]][j]; dp[i][j] = mn[i] + a[i]; if (prevv[i] >= j) { dp[i][j] = min(dp[i][j], dp[prevv[i]][j]); } } } } printf("%d\n", dp[n][k]); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 308 KB | Output is correct |
3 | Correct | 1 ms | 312 KB | Output is correct |
4 | Correct | 0 ms | 308 KB | Output is correct |
5 | Correct | 0 ms | 308 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 312 KB | Output is correct |
8 | Correct | 1 ms | 312 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Incorrect | 0 ms | 212 KB | Output isn't correct |
11 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 312 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Incorrect | 0 ms | 212 KB | Output isn't correct |
11 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 308 KB | Output is correct |
3 | Correct | 1 ms | 312 KB | Output is correct |
4 | Correct | 0 ms | 308 KB | Output is correct |
5 | Correct | 0 ms | 308 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 312 KB | Output is correct |
8 | Correct | 1 ms | 312 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Incorrect | 0 ms | 212 KB | Output isn't correct |
11 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 308 KB | Output is correct |
3 | Correct | 1 ms | 312 KB | Output is correct |
4 | Correct | 0 ms | 308 KB | Output is correct |
5 | Correct | 0 ms | 308 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 312 KB | Output is correct |
8 | Correct | 1 ms | 312 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Incorrect | 0 ms | 212 KB | Output isn't correct |
11 | Halted | 0 ms | 0 KB | - |