# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
140655 | rzbt | K개의 묶음 (IZhO14_blocks) | C++14 | 178 ms | 4176 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define MAXN 100005
typedef long long ll;
using namespace std;
ll n,k;
ll niz[MAXN];
ll dpp[MAXN],dp[MAXN];
stack<pair<ll,ll> > s;
int main()
{
scanf("%lld %lld", &n, &k);
for(ll i=1;i<=n;i++)
scanf("%lld",niz+i);
dp[0]=dpp[0]=1e9;
ll tmax=0;
for(ll i=1;i<=n;i++){
tmax=max(tmax,niz[i]);
dpp[i]=tmax;
}
for(ll j=1;j<k;j++){
//for(ll i=1;i<=n;i++)printf(" %d\n",dpp[i]);
//printf("\n\n\n");
for(ll i=1;i<=n;i++){
ll tS = dpp[i-1];
while(!s.empty() && niz[s.top().F] < niz[i]){
tS=min(tS,s.top().S);
s.pop();
}
if(!s.empty())dp[i]=min(dp[s.top().F],niz[i]+tS);
else dp[i]=niz[i]+tS;
s.push(mp(i,tS));
}
for(ll i=1;i<=n;i++)dpp[i]=dp[i];
while(!s.empty())s.pop();
}
printf("%lld",dpp[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... |