# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1092075 | juicy | K개의 묶음 (IZhO14_blocks) | C++17 | 178 ms | 4732 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
const long long inf = 1e18;
int n, k; cin >> n >> k;
vector dp(2, vector<long long>(n + 1, inf));
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
dp[1][i + 1] = max(i ? dp[1][i] : 0, (long long) a[i]);
}
for (int i = 1; i < k; ++i) {
vector<pair<int, long long>> st;
dp[i & 1 ^ 1][0] = inf;
for (int j = 0; j < n; ++j) {
long long x = dp[i & 1][j];
while (st.size() && st.back().first <= a[j]) {
x = min(x, st.back().second);
st.pop_back();
}
if (!st.size() || st.back().first + st.back().second > x + a[j]) {
st.push_back({a[j], x});
}
dp[i & 1 ^ 1][j + 1] = st.back().first + st.back().second;
}
}
cout << dp[k & 1][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... |