답안 #89851

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
89851 2018-12-18T15:22:26 Z Bodo171 K개의 묶음 (IZhO14_blocks) C++14
0 / 100
4 ms 1380 KB
#include <iostream>
#include <fstream>
#include <climits>
using namespace std;
const int nmax=100005;
long long v[nmax],dp[2][nmax],mn[nmax];
int st[nmax];
int n,k,i,j,use,u;
int main()
{
    //freopen("data.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>v[i];
    }
    for(i=0;i<=n;i++)
        dp[0][i]=1LL*1e15,dp[1][i]=1LL*1e15;
    mn[0]=1LL*1e15;dp[0][0]=0;
    for(int cnt=1;cnt<=k;cnt++)
    {
        use=1-use;u=0;
        for(i=1;i<=n;i++)
        {
            while(u>0&&v[i]>=v[st[u]])
                u--;
            st[++u]=v[i];
            mn[u]=min(mn[u-1],dp[1-use][st[u-1]]+v[i]);
            if(i>=cnt&&u==1)
                mn[u]=min(dp[1-use][cnt-1]+v[i],mn[u]);
            dp[use][i]=1LL*mn[u];
        }
        for(i=0;i<=n;i++)
            dp[1-use][i]=1LL*1e15;
    }
    cout<<dp[use][n];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Runtime error 3 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 768 KB Output is correct
2 Runtime error 3 ms 812 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 928 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 1380 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -