Submission #1026027

# Submission time Handle Problem Language Result Execution time Memory
1026027 2024-07-17T12:51:24 Z vjudge1 K blocks (IZhO14_blocks) C++17
53 / 100
901 ms 262144 KB
#include "bits/stdc++.h"
using namespace std;
    
#define int int64_t
#define pb push_back

const int lim=2e5+100;
int mod=1e9+7;

const int inf=INT_MAX;

using pii=pair<int,int>;

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Local  
    freopen(".in","r",stdin);freopen(".out","w",stdout);
#endif
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int dp[k+1][n];
    dp[1][0]=a[0];
    for(int i=1;i<n;i++){
        dp[1][i]=max(dp[1][i-1],a[i]);
    }
    if(k==1){
        cout<<dp[1][n-1];
        return 0;
    }
    int val[k+1][n];
    vector<int>stk;
    stk.pb(-1);
    multiset<int>goodvals[k+1];
    for(int i=0;i<=k;i++){
        goodvals[i].insert(inf);
    }
    for(int i=0;i<n;i++){
        for(int j=2;j<=k;j++){
            if(i)val[j][i]=dp[j-1][i-1];
            else val[j][i]=inf;
        }
        while(stk.back()!=-1&&a[stk.back()]<a[i]){
            for(int j=2;j<=k;j++){
                val[j][i]=min(val[j][i],val[j][stk.back()]-a[stk.back()]);
                goodvals[j].erase(goodvals[j].find(val[j][stk.back()]));
            }
            stk.pop_back();
        }
        for(int j=2;j<=k;j++){
            val[j][i]+=a[i];
            goodvals[j].insert(val[j][i]);
        }
        for(int j=2;j<=k;j++){
            dp[j][i]=*goodvals[j].begin();
        }
        stk.pb(i);
    }
    cout<<dp[k][n-1];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 452 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 452 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 452 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 460 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 460 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 460 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 460 KB Output is correct
53 Correct 1 ms 604 KB Output is correct
54 Correct 2 ms 856 KB Output is correct
55 Correct 1 ms 344 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 452 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 452 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 460 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 460 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 460 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 460 KB Output is correct
53 Correct 1 ms 604 KB Output is correct
54 Correct 2 ms 856 KB Output is correct
55 Correct 1 ms 344 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 11 ms 4440 KB Output is correct
59 Correct 5 ms 1628 KB Output is correct
60 Correct 14 ms 6492 KB Output is correct
61 Correct 138 ms 54688 KB Output is correct
62 Correct 465 ms 159824 KB Output is correct
63 Correct 20 ms 8028 KB Output is correct
64 Correct 187 ms 73820 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 1 ms 604 KB Output is correct
68 Correct 1 ms 348 KB Output is correct
69 Correct 1 ms 460 KB Output is correct
70 Correct 1 ms 604 KB Output is correct
71 Correct 63 ms 16476 KB Output is correct
72 Correct 3 ms 1112 KB Output is correct
73 Correct 16 ms 4444 KB Output is correct
74 Correct 3 ms 1628 KB Output is correct
75 Correct 23 ms 6492 KB Output is correct
76 Correct 238 ms 54736 KB Output is correct
77 Correct 696 ms 160344 KB Output is correct
78 Correct 22 ms 8028 KB Output is correct
79 Correct 321 ms 73812 KB Output is correct
80 Correct 6 ms 3420 KB Output is correct
81 Correct 77 ms 19128 KB Output is correct
82 Correct 783 ms 160340 KB Output is correct
83 Correct 1 ms 348 KB Output is correct
84 Correct 1 ms 604 KB Output is correct
85 Correct 196 ms 36912 KB Output is correct
86 Correct 2 ms 1116 KB Output is correct
87 Correct 39 ms 9376 KB Output is correct
88 Correct 4 ms 1628 KB Output is correct
89 Correct 47 ms 12116 KB Output is correct
90 Correct 622 ms 123520 KB Output is correct
91 Runtime error 901 ms 262144 KB Execution killed with signal 9
92 Halted 0 ms 0 KB -