# | 제출 시각UTC-0 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
173033 | juggernaut | K개의 묶음 (IZhO14_blocks) | C++14 | 269 ms | 40712 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Just try and the idea will come!
#include<bits/stdc++.h>
using namespace std;
int dp[101][100001],n,k,i,a[100001],j,tmp;
main(){
scanf("%d%d",&n,&k);
for(i=0;i<101;i++)
for(j=0;j<100001;j++)dp[i][j]=1e8;
dp[1][0]=0;
for(i=1;i<=n;i++)scanf("%d",&a[i]),dp[1][i]=max(dp[1][i-1],a[i]);
dp[1][0]=1e8;
for(i=2;i<=k;i++){
stack<pair<int,int>>st;
for(j=i;j<=n;j++){
tmp=dp[i-1][j-1];
while(!st.empty()&&a[st.top().first]<a[j]){
tmp=min(tmp,st.top().second);
st.pop();
}
if(!st.empty()&&j>=i)dp[i][j]=dp[i][st.top().first];
st.push({j,min(dp[i-1][j],tmp)});
if(j>=i)dp[i][j]=min(dp[i][j],tmp+a[j]);
}
}
printf("%d",dp[k][n]);
}
컴파일 시 표준 에러 (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... |