# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
671975 | ReLice | K개의 묶음 (IZhO14_blocks) | C++14 | 168 ms | 80636 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define ld long double
#define int long long
#define pb push_back
#define sz size()
#define fr first
#define sc second
void start(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const ll N=1e5+1;
const ll inf=1e9+7;
ll dp[105][N];
main(){
start();
ll n,k,i,j,b,mx=-1;
cin>>n>>k;
ll a[n+5];
for(i=1;i<=n;i++) cin>>a[i];
for(i=1;i<=n;i++) dp[1][i]=max(dp[1][i-1],a[i]);
for(i=2;i<=k;i++)
for(j=1;j<=n;j++)
dp[i][j]=inf;
for(i=2;i<=k;i++){
stack<pair<ll,ll>> st;
for(j=i;j<=n;j++){
ll tmp=dp[i-1][j-1];
while(!st.empty() && (st.top().fr<=a[j])){
tmp=min(tmp,st.top().sc);
st.pop();
}
if(st.empty() || st.top().fr+st.top().sc>=tmp+a[j])
st.push({a[j],tmp});
dp[i][j]=min(tmp+a[j],st.top().fr+st.top().sc);
}
}
cout<<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... |