답안 #308894

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
308894 2020-10-02T07:33:06 Z dangle1907 K개의 묶음 (IZhO14_blocks) C++14
0 / 100
1 ms 384 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
const int MAXN=1+1e5;
const int inf=1+1e9;
LL n,k,f[110][MAXN],a[MAXN];
deque<pair<LL,LL> > q;
int main()
{
#define TASK "ABC"
    //freopen(TASK ".inp","r",stdin);
    //freopen(TASK ".out","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>k;
    for(int i=1; i<=n; ++i)
    {
        cin>>a[i];
    }
    for(int i=1; i<=k; ++i)
    {
        for(int j=0; j<=n; ++j)
        {
            f[i][j]=inf;
        }
    }
    f[1][0]=0;
    for(int i=1; i<=n; ++i) f[1][i]=max(f[1][i-1],a[i]);
    for(int i=2; i<=k; ++i)
    {
        q.clear();
        for(int j=i; j<=n; ++j)
        {
            LL minf=f[i-1][j-1];
            while(!q.empty()&&a[j]>=a[q.back().se])
            {
                minf=min(minf,q.back().fi);
                q.pop_back();
            }
            //if(q.empty()) f[i][j]=min(f[i][0],minf+a[j]);
            //else f[i][j]=min(f[i][q.back().se],minf+a[j]);
            f[i][j]=min(f[i][j],minf+a[j]);
            q.push_back({minf,j});
            //cout<<i<<' '<<j<<' '<<minf<<' '<<f[i][j]<<endl;
        }
    }
    cout<<f[k][n];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Incorrect 0 ms 384 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Incorrect 0 ms 384 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Incorrect 0 ms 384 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Incorrect 0 ms 384 KB Output isn't correct
14 Halted 0 ms 0 KB -