# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
171756 |
2019-12-30T10:01:29 Z |
VEGAnn |
K blocks (IZhO14_blocks) |
C++14 |
|
354 ms |
45044 KB |
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define PB push_back
#define MP make_pair
#define ft first
#define sd second
#define pii pair<int, int>
#define pi3 pair<pii, int>
#define MP3(a,b,c) MP(MP(a, b), c)
using namespace std;
const int oo = 1e9;
const int N = 100100;
const int K = 110;
const int PW = 20;
stack<pi3> st;
int f[N][K], a[N], n, k;
int main(){
cin >> n >> k;
for (int i = 1; i <= n; i++)
cin >> a[i];
a[0] = oo;
for (int i = 0; i <= n; i++)
for (int j = 0; j <= k; j++)
f[i][j] = oo;
f[0][0] = 0;
for (int j = 1; j <= k; j++) {
while (sz(st)) st.pop();
st.push(MP3(0, oo, oo));
for (int i = 1; i <= n; i++){
pi3 nw = MP3(i, f[i - 1][j - 1], 0);
while (a[st.top().ft.ft] <= a[i]) {
nw.ft.sd = min(nw.ft.sd, st.top().ft.sd);
st.pop();
}
nw.sd = min(st.top().sd, nw.ft.sd + a[i]);
st.push(nw);
f[i][j] = nw.sd;
}
}
cout << f[n][k];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
128 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
380 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Correct |
2 ms |
276 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
380 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
396 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
4600 KB |
Output is correct |
2 |
Correct |
41 ms |
19580 KB |
Output is correct |
3 |
Correct |
51 ms |
19636 KB |
Output is correct |
4 |
Correct |
102 ms |
19704 KB |
Output is correct |
5 |
Correct |
287 ms |
44536 KB |
Output is correct |
6 |
Correct |
105 ms |
44408 KB |
Output is correct |
7 |
Correct |
215 ms |
44536 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
760 KB |
Output is correct |
13 |
Correct |
3 ms |
760 KB |
Output is correct |
14 |
Correct |
26 ms |
4728 KB |
Output is correct |
15 |
Correct |
11 ms |
4732 KB |
Output is correct |
16 |
Correct |
14 ms |
4728 KB |
Output is correct |
17 |
Correct |
41 ms |
19960 KB |
Output is correct |
18 |
Correct |
46 ms |
19960 KB |
Output is correct |
19 |
Correct |
101 ms |
19960 KB |
Output is correct |
20 |
Correct |
271 ms |
44536 KB |
Output is correct |
21 |
Correct |
95 ms |
44536 KB |
Output is correct |
22 |
Correct |
174 ms |
44536 KB |
Output is correct |
23 |
Correct |
92 ms |
44408 KB |
Output is correct |
24 |
Correct |
108 ms |
44504 KB |
Output is correct |
25 |
Correct |
281 ms |
44536 KB |
Output is correct |
26 |
Correct |
3 ms |
760 KB |
Output is correct |
27 |
Correct |
3 ms |
760 KB |
Output is correct |
28 |
Correct |
27 ms |
4856 KB |
Output is correct |
29 |
Correct |
11 ms |
4856 KB |
Output is correct |
30 |
Correct |
15 ms |
4856 KB |
Output is correct |
31 |
Correct |
43 ms |
20120 KB |
Output is correct |
32 |
Correct |
48 ms |
20188 KB |
Output is correct |
33 |
Correct |
105 ms |
20088 KB |
Output is correct |
34 |
Correct |
354 ms |
45044 KB |
Output is correct |
35 |
Correct |
98 ms |
44892 KB |
Output is correct |
36 |
Correct |
184 ms |
44988 KB |
Output is correct |
37 |
Correct |
11 ms |
4728 KB |
Output is correct |
38 |
Correct |
23 ms |
4732 KB |
Output is correct |
39 |
Correct |
3 ms |
760 KB |
Output is correct |
40 |
Correct |
3 ms |
760 KB |
Output is correct |
41 |
Correct |
2 ms |
376 KB |
Output is correct |
42 |
Correct |
2 ms |
376 KB |
Output is correct |