답안 #276451

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
276451 2020-08-20T12:55:52 Z mosiashvililuka K개의 묶음 (IZhO14_blocks) C++14
100 / 100
185 ms 172408 KB
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,i,j,ii,jj,zx,xc,fen[1000009],f[100009],k[100009];
long long dp[100009][109],pr[100009][109];
stack <int> s;
void upd(int q, int w){
    while(q<=1000002){
        fen[q]=max(fen[q],w);
        q=q+(q&(-q));
    }
}
int read(int q){
    int jm=0;
    while(q>=1){
        if(jm<fen[q]) jm=fen[q];
        q=q-(q&(-q));
    }
    return jm;
}
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    /*printf("%d%d",&a,&b);
    scanf("\n");*/
    cin>>a>>b;
    for(i=1; i<=a; i++){
        cin>>f[i];
        //scanf("%d",&f[i]);
        //k[i]=read(1000001-f[i]);
        //cout<<k[i]<<" ";
        //upd(1000001-f[i]+1,i);
    }
    //cout<<endl;
    zx=0;
    for(i=0; i<=a; i++){
        for(j=0; j<=b; j++) pr[i][j]=999999999999999999LL;
        for(j=0; j<=b; j++) dp[i][j]=999999999999999999LL;
    }
    dp[0][0]=0;zx=0;
    for(i=1; i<=a; i++){
        while(s.size()>0&&f[s.top()]<f[i]){
            for(j=1; j<b; j++){
                pr[i][j]=min(pr[i][j],pr[s.top()][j]-f[s.top()]+f[i]);
            }
            s.pop();
        }
        if(s.size()>0){
            for(j=1; j<b; j++){
                pr[i][j]=min(pr[i][j],pr[s.top()][j]);
            }
        }
        for(j=1; j<b; j++){
            pr[i][j]=min(pr[i][j],dp[i-1][j]+f[i]);
        }
        for(j=2; j<=b; j++){
            dp[i][j]=dp[i-1][j-1]+f[i];
            if(dp[i][j]>pr[i][j-1]) dp[i][j]=pr[i][j-1];
        }
zx=max(zx,f[i]);
dp[i][1]=zx;
        s.push(i);
    }
    //cout<<pr[1][1]<<endl;
    cout<<dp[a][b];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 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 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 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 1 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 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 504 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 17536 KB Output is correct
2 Correct 43 ms 76696 KB Output is correct
3 Correct 48 ms 76664 KB Output is correct
4 Correct 69 ms 76664 KB Output is correct
5 Correct 183 ms 172024 KB Output is correct
6 Correct 107 ms 172116 KB Output is correct
7 Correct 139 ms 172028 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 2024 KB Output is correct
13 Correct 1 ms 2048 KB Output is correct
14 Correct 19 ms 17536 KB Output is correct
15 Correct 10 ms 17536 KB Output is correct
16 Correct 14 ms 17536 KB Output is correct
17 Correct 41 ms 76664 KB Output is correct
18 Correct 49 ms 76792 KB Output is correct
19 Correct 83 ms 76664 KB Output is correct
20 Correct 185 ms 172024 KB Output is correct
21 Correct 108 ms 172024 KB Output is correct
22 Correct 166 ms 172128 KB Output is correct
23 Correct 98 ms 172040 KB Output is correct
24 Correct 127 ms 172024 KB Output is correct
25 Correct 185 ms 172144 KB Output is correct
26 Correct 2 ms 2048 KB Output is correct
27 Correct 2 ms 2048 KB Output is correct
28 Correct 17 ms 17536 KB Output is correct
29 Correct 10 ms 17536 KB Output is correct
30 Correct 16 ms 17536 KB Output is correct
31 Correct 42 ms 76792 KB Output is correct
32 Correct 58 ms 76792 KB Output is correct
33 Correct 68 ms 76792 KB Output is correct
34 Correct 179 ms 172296 KB Output is correct
35 Correct 114 ms 172408 KB Output is correct
36 Correct 146 ms 172288 KB Output is correct
37 Correct 14 ms 17536 KB Output is correct
38 Correct 18 ms 17536 KB Output is correct
39 Correct 2 ms 2048 KB Output is correct
40 Correct 2 ms 2048 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct