# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1039072 | ttviet2805 | K개의 묶음 (IZhO14_blocks) | C++14 | 241 ms | 82024 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define II pair <int, int>
#define fi first
#define se second
#define all(S) S.begin(), S.end()
const int INF = 1e15;
const int N = 1e5 + 5;
int n, a[N], K;
void in() {
cin >> n >> K;
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
vector <vector <int>> f(K + 1, vector <int> (n + 5, INF));
f[0][0] = 0;
for(int X = 1; X <= K; X++) {
stack <II> st;
st.push({X - 1, f[X - 1][X - 1]});
for(int i = X; i <= n; i++) {
int curMin = INF;
while(!st.empty() && a[i] >= a[st.top().fi]) {
curMin = min(curMin, st.top().se);
st.pop();
}
int res = curMin;
if(!st.empty()) {
res = min(curMin, f[X - 1][st.top().fi]);
f[X][i] = f[X][st.top().fi];
}
f[X][i] = min(f[X][i], res + a[i]);
curMin = min(curMin, f[X - 1][i]);
st.push({i, curMin});
}
}
// for(int X = 1; X <= K; X++) {
// for(int i = 1; i <= n; i++) {
// cout << "#: " << X << ' ' << i << "\t" << f[X][i] << endl;
// }
// }
cout << f[K][n] << '\n';
}
void process() {
}
int32_t main() {
if(fopen("trash.inp", "r"))
freopen("trash.inp", "r", stdin), freopen("trash.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
while(T--) {
in();
process();
}
}
컴파일 시 표준 에러 (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... |