# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
38200 | Talant | K개의 묶음 (IZhO14_blocks) | C++14 | 229 ms | 81972 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair
using namespace std;
typedef long long ll;
const ll inf = (ll)1e18 + 7;
const int N = (int)1e5 + 7;
int n,k;
int a[N];
ll dp[101][N];
int main () {
cin >> n >> k;
for (int i = 1; i <= n; i ++)
scanf ("%d", &a[i]);
memset(dp,0x3f3f3f3f,sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= k; i ++) {
stack <pair<ll,ll> > st;
st.push({inf,inf});
for (int j = i; j <= n; j ++) {
ll cur = dp[i - 1][j - 1];
while (!st.empty() && st.top().fr <= a[j]) {
cur = min(cur,st.top().sc);
st.pop();
}
dp[i][j] = min(st.top().fr + st.top().sc,cur + a[j]);
if (st.top().fr + st.top().sc > cur + a[j])
st.push({a[j],cur});
}
}
cout << dp[k][n] << endl;
}
컴파일 시 표준 에러 (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... |