# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
529951 | tht2005 | K blocks (IZhO14_blocks) | C++17 | 99 ms | 2928 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int INF = 0x3f3f3f3f;
int n, kk, a[N], L[N], f[N], g[N], h[N];
int main() {
scanf("%d %d", &n, &kk);
for(int i = 1; i <= n; ++i) {
scanf("%d", a + i);
int k = i - 1;
while(k > 0 && a[i] >= a[k])
k = L[k];
L[i] = k;
}
f[0] = 0;
for(int i = 1; i <= n; ++i)
f[i] = max(f[i - 1], a[i]);
for(int i = 2; i <= kk; ++i) {
for(int j = 0; j <= n; ++j) {
g[j] = f[j];
f[j] = INF;
}
h[i - 1] = INF;
for(int j = i; j <= n; ++j) {
h[j] = g[j - 1];
for(int k = j - 1; k > L[j]; k = L[k])
h[j] = min(h[j], h[k]);
f[j] = min(f[L[j]], h[j] + a[j]);
}
}
printf("%d", f[n]);
return 0;
}
컴파일 시 표준 에러 (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... |