이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
const int K=1e2+5;
typedef pair<int,int> ii;
int n,k;
int a[N];
int f[K][N];
void dp(){
memset(f,1,sizeof(f));
f[1][0]=0;
for(int i=1;i<=n;i++) f[1][i]=max(f[1][i-1],a[i]);
for(int i=2;i<=k;i++){
stack<ii> st;
for(int j=i;j<=n;j++){
int tmp=f[i-1][j-1];
while(st.size()&&a[st.top().first]<=a[j]){
tmp=min(tmp,st.top().second);
st.pop();
}
int p=st.size()?st.top().first:0;
f[i][j]=min(f[i][p],tmp+a[j]);
st.push({j,tmp});
}
}
cout<<f[k][n];
}
main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>a[i];
dp();
}
컴파일 시 표준 에러 (stderr) 메시지
blocks.cpp:33:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# | 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... |