# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
88641 |
2018-12-07T08:24:21 Z |
ABCD |
K blocks (IZhO14_blocks) |
C++14 |
|
234 ms |
51196 KB |
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
const int K=1e2+5;
typedef pair<int,int> ii;
int n,k;
int a[N];
int f[K][N];
void dp(){
memset(f,0x3f,sizeof(f));
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++){
stack<ii> st;
for(int j=i;j<=n;j++){
int tmp=f[i-1][j-1];
while(st.size()&&a[st.top().first]<=a[j]){
tmp=min(tmp,st.top().second);
st.pop();
}
int p=st.size()?st.top().first:0;
f[i][j]=min(f[i][p],tmp+a[j]);
st.push({j,tmp});
}
}
cout<<f[k][n];
}
main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>a[i];
dp();
}
Compilation message
blocks.cpp:33:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
41464 KB |
Output is correct |
2 |
Correct |
34 ms |
41564 KB |
Output is correct |
3 |
Correct |
34 ms |
41636 KB |
Output is correct |
4 |
Correct |
34 ms |
41636 KB |
Output is correct |
5 |
Correct |
33 ms |
41636 KB |
Output is correct |
6 |
Correct |
33 ms |
41636 KB |
Output is correct |
7 |
Correct |
33 ms |
41636 KB |
Output is correct |
8 |
Correct |
34 ms |
41756 KB |
Output is correct |
9 |
Correct |
33 ms |
41756 KB |
Output is correct |
10 |
Correct |
34 ms |
41756 KB |
Output is correct |
11 |
Correct |
33 ms |
41756 KB |
Output is correct |
12 |
Correct |
34 ms |
41756 KB |
Output is correct |
13 |
Correct |
33 ms |
41756 KB |
Output is correct |
14 |
Correct |
34 ms |
41756 KB |
Output is correct |
15 |
Correct |
35 ms |
41756 KB |
Output is correct |
16 |
Correct |
34 ms |
41756 KB |
Output is correct |
17 |
Correct |
38 ms |
41756 KB |
Output is correct |
18 |
Correct |
37 ms |
41756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
41756 KB |
Output is correct |
2 |
Correct |
37 ms |
41756 KB |
Output is correct |
3 |
Correct |
37 ms |
41756 KB |
Output is correct |
4 |
Correct |
35 ms |
41756 KB |
Output is correct |
5 |
Correct |
38 ms |
41756 KB |
Output is correct |
6 |
Correct |
36 ms |
41756 KB |
Output is correct |
7 |
Correct |
38 ms |
41756 KB |
Output is correct |
8 |
Correct |
35 ms |
41756 KB |
Output is correct |
9 |
Correct |
37 ms |
41756 KB |
Output is correct |
10 |
Correct |
35 ms |
41756 KB |
Output is correct |
11 |
Correct |
34 ms |
41756 KB |
Output is correct |
12 |
Correct |
27 ms |
41756 KB |
Output is correct |
13 |
Correct |
34 ms |
41756 KB |
Output is correct |
14 |
Correct |
33 ms |
41756 KB |
Output is correct |
15 |
Correct |
34 ms |
41756 KB |
Output is correct |
16 |
Correct |
34 ms |
41756 KB |
Output is correct |
17 |
Correct |
34 ms |
41756 KB |
Output is correct |
18 |
Correct |
35 ms |
41756 KB |
Output is correct |
19 |
Correct |
33 ms |
41756 KB |
Output is correct |
20 |
Correct |
33 ms |
41756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
41756 KB |
Output is correct |
2 |
Correct |
35 ms |
41756 KB |
Output is correct |
3 |
Correct |
33 ms |
41756 KB |
Output is correct |
4 |
Correct |
33 ms |
41756 KB |
Output is correct |
5 |
Correct |
33 ms |
41756 KB |
Output is correct |
6 |
Correct |
34 ms |
41756 KB |
Output is correct |
7 |
Correct |
33 ms |
41756 KB |
Output is correct |
8 |
Correct |
33 ms |
41756 KB |
Output is correct |
9 |
Correct |
34 ms |
41756 KB |
Output is correct |
10 |
Correct |
33 ms |
41884 KB |
Output is correct |
11 |
Correct |
34 ms |
41884 KB |
Output is correct |
12 |
Correct |
34 ms |
41884 KB |
Output is correct |
13 |
Correct |
35 ms |
41884 KB |
Output is correct |
14 |
Correct |
37 ms |
41884 KB |
Output is correct |
15 |
Correct |
35 ms |
41884 KB |
Output is correct |
16 |
Correct |
35 ms |
41884 KB |
Output is correct |
17 |
Correct |
34 ms |
41884 KB |
Output is correct |
18 |
Correct |
34 ms |
41916 KB |
Output is correct |
19 |
Correct |
34 ms |
41916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
41916 KB |
Output is correct |
2 |
Correct |
39 ms |
41984 KB |
Output is correct |
3 |
Correct |
43 ms |
41984 KB |
Output is correct |
4 |
Correct |
89 ms |
41984 KB |
Output is correct |
5 |
Correct |
197 ms |
42332 KB |
Output is correct |
6 |
Correct |
48 ms |
42332 KB |
Output is correct |
7 |
Correct |
112 ms |
42332 KB |
Output is correct |
8 |
Correct |
34 ms |
42332 KB |
Output is correct |
9 |
Correct |
38 ms |
42332 KB |
Output is correct |
10 |
Correct |
37 ms |
42332 KB |
Output is correct |
11 |
Correct |
37 ms |
42332 KB |
Output is correct |
12 |
Correct |
37 ms |
42332 KB |
Output is correct |
13 |
Correct |
38 ms |
42332 KB |
Output is correct |
14 |
Correct |
56 ms |
42332 KB |
Output is correct |
15 |
Correct |
35 ms |
42332 KB |
Output is correct |
16 |
Correct |
42 ms |
42332 KB |
Output is correct |
17 |
Correct |
38 ms |
42536 KB |
Output is correct |
18 |
Correct |
44 ms |
42964 KB |
Output is correct |
19 |
Correct |
103 ms |
43280 KB |
Output is correct |
20 |
Correct |
234 ms |
44204 KB |
Output is correct |
21 |
Correct |
52 ms |
44772 KB |
Output is correct |
22 |
Correct |
129 ms |
45604 KB |
Output is correct |
23 |
Correct |
44 ms |
46120 KB |
Output is correct |
24 |
Correct |
63 ms |
46808 KB |
Output is correct |
25 |
Correct |
233 ms |
47564 KB |
Output is correct |
26 |
Correct |
33 ms |
47564 KB |
Output is correct |
27 |
Correct |
33 ms |
47564 KB |
Output is correct |
28 |
Correct |
50 ms |
47564 KB |
Output is correct |
29 |
Correct |
34 ms |
47564 KB |
Output is correct |
30 |
Correct |
38 ms |
47564 KB |
Output is correct |
31 |
Correct |
42 ms |
47768 KB |
Output is correct |
32 |
Correct |
44 ms |
48320 KB |
Output is correct |
33 |
Correct |
98 ms |
48624 KB |
Output is correct |
34 |
Correct |
216 ms |
49800 KB |
Output is correct |
35 |
Correct |
48 ms |
50376 KB |
Output is correct |
36 |
Correct |
125 ms |
51196 KB |
Output is correct |
37 |
Correct |
39 ms |
51196 KB |
Output is correct |
38 |
Correct |
52 ms |
51196 KB |
Output is correct |
39 |
Correct |
37 ms |
51196 KB |
Output is correct |
40 |
Correct |
36 ms |
51196 KB |
Output is correct |
41 |
Correct |
33 ms |
51196 KB |
Output is correct |
42 |
Correct |
33 ms |
51196 KB |
Output is correct |