# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
105368 | 2019-04-11T14:39:02 Z | thanhtraf | K blocks (IZhO14_blocks) | C++11 | 681 ms | 41116 KB |
#include<bits/stdc++.h> using namespace std; #define task "data" const int maxn=1e5+5; const int vc=-1e9+5; int dp[maxn][100] , n , a[maxn] , k ; typedef pair<int,int> ii; #define fi first #define se second main() { //freopen(task".inp","r",stdin); // freopen(task".out","w",stdout); scanf("%d%d",&n,&k); for (int i=1;i<=n;i++) scanf("%d",&a[i]); memset(dp, 0x3f, sizeof dp); //cout<<dp[1][0]; dp[0][1]=0; for (int i=1;i<=n;i++) { dp[i][1]=max(a[i],dp[i-1][1]); // cout<<dp[i][1]; } for (int i=2;i<=k;i++) { stack<ii> s; for (int j=i;j<=n;j++) { int minf=dp[j-1][i-1]; while (s.size()&&a[j]>=a[s.top().se]) { minf=min(minf,s.top().fi); s.pop(); } //cout<<minf<<endl; if(s.size()==0) dp[j][i]=dp[0][i]; else dp[j][i]=dp[s.top().se][i]; dp[j][i]=min(minf+a[j],dp[j][i]); s.push(ii(minf,j));; } } cout<<dp[n][k]; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 35 ms | 39544 KB | Output is correct |
2 | Correct | 33 ms | 39416 KB | Output is correct |
3 | Correct | 33 ms | 39416 KB | Output is correct |
4 | Correct | 34 ms | 39444 KB | Output is correct |
5 | Correct | 32 ms | 39544 KB | Output is correct |
6 | Correct | 33 ms | 39544 KB | Output is correct |
7 | Correct | 33 ms | 39544 KB | Output is correct |
8 | Correct | 33 ms | 39416 KB | Output is correct |
9 | Correct | 36 ms | 39544 KB | Output is correct |
10 | Correct | 31 ms | 39552 KB | Output is correct |
11 | Correct | 38 ms | 39420 KB | Output is correct |
12 | Correct | 34 ms | 39544 KB | Output is correct |
13 | Correct | 34 ms | 39544 KB | Output is correct |
14 | Correct | 36 ms | 39544 KB | Output is correct |
15 | Correct | 35 ms | 39544 KB | Output is correct |
16 | Correct | 37 ms | 39416 KB | Output is correct |
17 | Correct | 35 ms | 39544 KB | Output is correct |
18 | Correct | 34 ms | 39416 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 38 ms | 39416 KB | Output is correct |
2 | Correct | 38 ms | 39416 KB | Output is correct |
3 | Correct | 34 ms | 39416 KB | Output is correct |
4 | Correct | 32 ms | 39500 KB | Output is correct |
5 | Correct | 33 ms | 39544 KB | Output is correct |
6 | Correct | 33 ms | 39552 KB | Output is correct |
7 | Correct | 34 ms | 39416 KB | Output is correct |
8 | Correct | 37 ms | 39516 KB | Output is correct |
9 | Correct | 32 ms | 39416 KB | Output is correct |
10 | Correct | 35 ms | 39544 KB | Output is correct |
11 | Correct | 38 ms | 39420 KB | Output is correct |
12 | Correct | 34 ms | 39544 KB | Output is correct |
13 | Correct | 37 ms | 39416 KB | Output is correct |
14 | Correct | 33 ms | 39544 KB | Output is correct |
15 | Correct | 38 ms | 39416 KB | Output is correct |
16 | Correct | 34 ms | 39416 KB | Output is correct |
17 | Correct | 32 ms | 39416 KB | Output is correct |
18 | Correct | 34 ms | 39424 KB | Output is correct |
19 | Correct | 38 ms | 39420 KB | Output is correct |
20 | Correct | 32 ms | 39424 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 34 ms | 39544 KB | Output is correct |
2 | Correct | 36 ms | 39544 KB | Output is correct |
3 | Correct | 34 ms | 39416 KB | Output is correct |
4 | Correct | 35 ms | 39544 KB | Output is correct |
5 | Correct | 34 ms | 39544 KB | Output is correct |
6 | Correct | 34 ms | 39416 KB | Output is correct |
7 | Correct | 34 ms | 39468 KB | Output is correct |
8 | Correct | 38 ms | 39416 KB | Output is correct |
9 | Correct | 37 ms | 39416 KB | Output is correct |
10 | Correct | 37 ms | 39416 KB | Output is correct |
11 | Correct | 37 ms | 39544 KB | Output is correct |
12 | Correct | 34 ms | 39544 KB | Output is correct |
13 | Correct | 33 ms | 39384 KB | Output is correct |
14 | Correct | 33 ms | 39424 KB | Output is correct |
15 | Correct | 35 ms | 39536 KB | Output is correct |
16 | Correct | 32 ms | 39544 KB | Output is correct |
17 | Correct | 33 ms | 39416 KB | Output is correct |
18 | Correct | 33 ms | 39416 KB | Output is correct |
19 | Correct | 33 ms | 39428 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 38 ms | 39544 KB | Output is correct |
2 | Correct | 43 ms | 39936 KB | Output is correct |
3 | Correct | 52 ms | 39928 KB | Output is correct |
4 | Correct | 170 ms | 40056 KB | Output is correct |
5 | Correct | 609 ms | 40628 KB | Output is correct |
6 | Correct | 54 ms | 40568 KB | Output is correct |
7 | Correct | 268 ms | 40568 KB | Output is correct |
8 | Correct | 37 ms | 39544 KB | Output is correct |
9 | Correct | 35 ms | 39416 KB | Output is correct |
10 | Correct | 39 ms | 39416 KB | Output is correct |
11 | Correct | 38 ms | 39416 KB | Output is correct |
12 | Correct | 33 ms | 39424 KB | Output is correct |
13 | Correct | 34 ms | 39416 KB | Output is correct |
14 | Correct | 48 ms | 39544 KB | Output is correct |
15 | Correct | 34 ms | 39544 KB | Output is correct |
16 | Correct | 39 ms | 39544 KB | Output is correct |
17 | Correct | 41 ms | 39928 KB | Output is correct |
18 | Correct | 63 ms | 39928 KB | Output is correct |
19 | Correct | 188 ms | 40056 KB | Output is correct |
20 | Correct | 621 ms | 40696 KB | Output is correct |
21 | Correct | 60 ms | 40568 KB | Output is correct |
22 | Correct | 311 ms | 40568 KB | Output is correct |
23 | Correct | 50 ms | 40568 KB | Output is correct |
24 | Correct | 90 ms | 40568 KB | Output is correct |
25 | Correct | 484 ms | 40728 KB | Output is correct |
26 | Correct | 32 ms | 39544 KB | Output is correct |
27 | Correct | 33 ms | 39544 KB | Output is correct |
28 | Correct | 69 ms | 39616 KB | Output is correct |
29 | Correct | 33 ms | 39544 KB | Output is correct |
30 | Correct | 47 ms | 39672 KB | Output is correct |
31 | Correct | 39 ms | 39932 KB | Output is correct |
32 | Correct | 51 ms | 40160 KB | Output is correct |
33 | Correct | 177 ms | 40180 KB | Output is correct |
34 | Correct | 681 ms | 41116 KB | Output is correct |
35 | Correct | 53 ms | 40912 KB | Output is correct |
36 | Correct | 263 ms | 40876 KB | Output is correct |
37 | Correct | 41 ms | 39580 KB | Output is correct |
38 | Correct | 52 ms | 39544 KB | Output is correct |
39 | Correct | 36 ms | 39544 KB | Output is correct |
40 | Correct | 34 ms | 39544 KB | Output is correct |
41 | Correct | 37 ms | 39456 KB | Output is correct |
42 | Correct | 34 ms | 39544 KB | Output is correct |