# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1101528 | tuan19a | K개의 묶음 (IZhO14_blocks) | C++14 | 149 ms | 83456 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define el "\n"
#define FILE "test1"
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define bit(mask,i) ((mask>>i) & 1)
const int N=1e5+2;
const ll oo=1e18;
const int mod=1e9+7;
const int base=31;
const int dx[4]={0, 0, 1, -1};
const int dy[4]={1, -1, 0, 0};
using namespace std;
int n,k,a[N],dp[N][102],l[N],rmq[N][25];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
if (fopen(FILE".inp","r"))
{
freopen(FILE".inp","r",stdin);
freopen(FILE".out","w",stdout);
}
cin>>n>>k;
for (int i=1;i<=n;i++)
cin>>a[i];
memset(dp,0x3f,sizeof dp);
dp[0][1]=0;
for (int i=1;i<=n;i++) dp[i][1]=max(dp[i-1][1],a[i]);
for (int i=2;i<=k;i++)
{
stack <pii> s;
for (int j=i;j<=n;j++)
{
int minn=dp[j-1][i-1];
while (!s.empty() && a[j]>=a[s.top().se]) minn=min(minn,s.top().fi),s.pop();
int pos=0;
if (!s.empty()) pos=s.top().se;
dp[j][i]=min(dp[pos][i],minn+a[j]);
s.push({minn,j});
}
}
cout<<dp[n][k];
}
/** /\_/\
* (= ._.)
* / >AC \>AC
**/
컴파일 시 표준 에러 (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... |