# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1092073 |
2024-09-23T04:14:26 Z |
juicy |
K blocks (IZhO14_blocks) |
C++17 |
|
104 ms |
159904 KB |
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 1e5 + 5, K = 101;
int n, k;
int a[N];
long long dp[N][K], f[N][K];
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
memset(f, 0x3f, sizeof(f));
memset(dp, 0x3f, sizeof(dp));
dp[0][0] = 0;
vector<int> st;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= k; ++j) {
f[i][j] = dp[i - 1][j];
}
while (st.size() && a[st.back()] <= a[i]) {
for (int j = 0; j <= k; ++j) {
f[i][j] = min(f[i][j], f[st.back()][j]);
}
st.pop_back();
}
for (int j = 1; j <= k; ++j) {
dp[i][j] = min(dp[i][j], f[i][j - 1] + a[i]);
}
if (st.size()) {
for (int j = 1; j <= k; ++j) {
dp[i][j] = min(dp[i][j], dp[st.back()][j]);
}
}
st.push_back(i);
}
cout << dp[n][k];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
158548 KB |
Output is correct |
2 |
Correct |
72 ms |
158548 KB |
Output is correct |
3 |
Correct |
69 ms |
158544 KB |
Output is correct |
4 |
Correct |
69 ms |
158548 KB |
Output is correct |
5 |
Correct |
70 ms |
158384 KB |
Output is correct |
6 |
Correct |
81 ms |
158548 KB |
Output is correct |
7 |
Correct |
74 ms |
158408 KB |
Output is correct |
8 |
Correct |
72 ms |
158548 KB |
Output is correct |
9 |
Correct |
70 ms |
158548 KB |
Output is correct |
10 |
Correct |
70 ms |
158492 KB |
Output is correct |
11 |
Correct |
69 ms |
158548 KB |
Output is correct |
12 |
Correct |
68 ms |
158544 KB |
Output is correct |
13 |
Correct |
70 ms |
158544 KB |
Output is correct |
14 |
Correct |
71 ms |
158548 KB |
Output is correct |
15 |
Correct |
71 ms |
158548 KB |
Output is correct |
16 |
Correct |
72 ms |
158476 KB |
Output is correct |
17 |
Correct |
70 ms |
158404 KB |
Output is correct |
18 |
Correct |
69 ms |
158528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
158324 KB |
Output is correct |
2 |
Correct |
71 ms |
158548 KB |
Output is correct |
3 |
Correct |
70 ms |
158544 KB |
Output is correct |
4 |
Correct |
75 ms |
158548 KB |
Output is correct |
5 |
Correct |
67 ms |
158548 KB |
Output is correct |
6 |
Correct |
69 ms |
158412 KB |
Output is correct |
7 |
Correct |
69 ms |
158548 KB |
Output is correct |
8 |
Correct |
70 ms |
158444 KB |
Output is correct |
9 |
Correct |
72 ms |
158544 KB |
Output is correct |
10 |
Correct |
70 ms |
158544 KB |
Output is correct |
11 |
Correct |
73 ms |
158548 KB |
Output is correct |
12 |
Correct |
71 ms |
158548 KB |
Output is correct |
13 |
Correct |
73 ms |
158548 KB |
Output is correct |
14 |
Correct |
73 ms |
158548 KB |
Output is correct |
15 |
Correct |
79 ms |
158548 KB |
Output is correct |
16 |
Correct |
71 ms |
158332 KB |
Output is correct |
17 |
Correct |
71 ms |
158364 KB |
Output is correct |
18 |
Correct |
72 ms |
158444 KB |
Output is correct |
19 |
Correct |
77 ms |
158548 KB |
Output is correct |
20 |
Correct |
62 ms |
158336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
158548 KB |
Output is correct |
2 |
Correct |
72 ms |
158548 KB |
Output is correct |
3 |
Correct |
69 ms |
158544 KB |
Output is correct |
4 |
Correct |
69 ms |
158548 KB |
Output is correct |
5 |
Correct |
70 ms |
158384 KB |
Output is correct |
6 |
Correct |
81 ms |
158548 KB |
Output is correct |
7 |
Correct |
74 ms |
158408 KB |
Output is correct |
8 |
Correct |
72 ms |
158548 KB |
Output is correct |
9 |
Correct |
70 ms |
158548 KB |
Output is correct |
10 |
Correct |
70 ms |
158492 KB |
Output is correct |
11 |
Correct |
69 ms |
158548 KB |
Output is correct |
12 |
Correct |
68 ms |
158544 KB |
Output is correct |
13 |
Correct |
70 ms |
158544 KB |
Output is correct |
14 |
Correct |
71 ms |
158548 KB |
Output is correct |
15 |
Correct |
71 ms |
158548 KB |
Output is correct |
16 |
Correct |
72 ms |
158476 KB |
Output is correct |
17 |
Correct |
70 ms |
158404 KB |
Output is correct |
18 |
Correct |
69 ms |
158528 KB |
Output is correct |
19 |
Correct |
70 ms |
158324 KB |
Output is correct |
20 |
Correct |
71 ms |
158548 KB |
Output is correct |
21 |
Correct |
70 ms |
158544 KB |
Output is correct |
22 |
Correct |
75 ms |
158548 KB |
Output is correct |
23 |
Correct |
67 ms |
158548 KB |
Output is correct |
24 |
Correct |
69 ms |
158412 KB |
Output is correct |
25 |
Correct |
69 ms |
158548 KB |
Output is correct |
26 |
Correct |
70 ms |
158444 KB |
Output is correct |
27 |
Correct |
72 ms |
158544 KB |
Output is correct |
28 |
Correct |
70 ms |
158544 KB |
Output is correct |
29 |
Correct |
73 ms |
158548 KB |
Output is correct |
30 |
Correct |
71 ms |
158548 KB |
Output is correct |
31 |
Correct |
73 ms |
158548 KB |
Output is correct |
32 |
Correct |
73 ms |
158548 KB |
Output is correct |
33 |
Correct |
79 ms |
158548 KB |
Output is correct |
34 |
Correct |
71 ms |
158332 KB |
Output is correct |
35 |
Correct |
71 ms |
158364 KB |
Output is correct |
36 |
Correct |
72 ms |
158444 KB |
Output is correct |
37 |
Correct |
77 ms |
158548 KB |
Output is correct |
38 |
Correct |
62 ms |
158336 KB |
Output is correct |
39 |
Correct |
63 ms |
158548 KB |
Output is correct |
40 |
Correct |
64 ms |
158536 KB |
Output is correct |
41 |
Correct |
63 ms |
158344 KB |
Output is correct |
42 |
Correct |
63 ms |
158456 KB |
Output is correct |
43 |
Correct |
63 ms |
158400 KB |
Output is correct |
44 |
Correct |
63 ms |
158548 KB |
Output is correct |
45 |
Correct |
63 ms |
158520 KB |
Output is correct |
46 |
Correct |
63 ms |
158428 KB |
Output is correct |
47 |
Correct |
62 ms |
158496 KB |
Output is correct |
48 |
Correct |
75 ms |
158548 KB |
Output is correct |
49 |
Correct |
63 ms |
158544 KB |
Output is correct |
50 |
Correct |
62 ms |
158544 KB |
Output is correct |
51 |
Correct |
63 ms |
158548 KB |
Output is correct |
52 |
Correct |
62 ms |
158544 KB |
Output is correct |
53 |
Correct |
70 ms |
158544 KB |
Output is correct |
54 |
Correct |
72 ms |
158544 KB |
Output is correct |
55 |
Correct |
67 ms |
158544 KB |
Output is correct |
56 |
Correct |
72 ms |
158340 KB |
Output is correct |
57 |
Correct |
72 ms |
158360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
158548 KB |
Output is correct |
2 |
Correct |
72 ms |
158548 KB |
Output is correct |
3 |
Correct |
69 ms |
158544 KB |
Output is correct |
4 |
Correct |
69 ms |
158548 KB |
Output is correct |
5 |
Correct |
70 ms |
158384 KB |
Output is correct |
6 |
Correct |
81 ms |
158548 KB |
Output is correct |
7 |
Correct |
74 ms |
158408 KB |
Output is correct |
8 |
Correct |
72 ms |
158548 KB |
Output is correct |
9 |
Correct |
70 ms |
158548 KB |
Output is correct |
10 |
Correct |
70 ms |
158492 KB |
Output is correct |
11 |
Correct |
69 ms |
158548 KB |
Output is correct |
12 |
Correct |
68 ms |
158544 KB |
Output is correct |
13 |
Correct |
70 ms |
158544 KB |
Output is correct |
14 |
Correct |
71 ms |
158548 KB |
Output is correct |
15 |
Correct |
71 ms |
158548 KB |
Output is correct |
16 |
Correct |
72 ms |
158476 KB |
Output is correct |
17 |
Correct |
70 ms |
158404 KB |
Output is correct |
18 |
Correct |
69 ms |
158528 KB |
Output is correct |
19 |
Correct |
70 ms |
158324 KB |
Output is correct |
20 |
Correct |
71 ms |
158548 KB |
Output is correct |
21 |
Correct |
70 ms |
158544 KB |
Output is correct |
22 |
Correct |
75 ms |
158548 KB |
Output is correct |
23 |
Correct |
67 ms |
158548 KB |
Output is correct |
24 |
Correct |
69 ms |
158412 KB |
Output is correct |
25 |
Correct |
69 ms |
158548 KB |
Output is correct |
26 |
Correct |
70 ms |
158444 KB |
Output is correct |
27 |
Correct |
72 ms |
158544 KB |
Output is correct |
28 |
Correct |
70 ms |
158544 KB |
Output is correct |
29 |
Correct |
73 ms |
158548 KB |
Output is correct |
30 |
Correct |
71 ms |
158548 KB |
Output is correct |
31 |
Correct |
73 ms |
158548 KB |
Output is correct |
32 |
Correct |
73 ms |
158548 KB |
Output is correct |
33 |
Correct |
79 ms |
158548 KB |
Output is correct |
34 |
Correct |
71 ms |
158332 KB |
Output is correct |
35 |
Correct |
71 ms |
158364 KB |
Output is correct |
36 |
Correct |
72 ms |
158444 KB |
Output is correct |
37 |
Correct |
77 ms |
158548 KB |
Output is correct |
38 |
Correct |
62 ms |
158336 KB |
Output is correct |
39 |
Correct |
63 ms |
158548 KB |
Output is correct |
40 |
Correct |
64 ms |
158536 KB |
Output is correct |
41 |
Correct |
63 ms |
158344 KB |
Output is correct |
42 |
Correct |
63 ms |
158456 KB |
Output is correct |
43 |
Correct |
63 ms |
158400 KB |
Output is correct |
44 |
Correct |
63 ms |
158548 KB |
Output is correct |
45 |
Correct |
63 ms |
158520 KB |
Output is correct |
46 |
Correct |
63 ms |
158428 KB |
Output is correct |
47 |
Correct |
62 ms |
158496 KB |
Output is correct |
48 |
Correct |
75 ms |
158548 KB |
Output is correct |
49 |
Correct |
63 ms |
158544 KB |
Output is correct |
50 |
Correct |
62 ms |
158544 KB |
Output is correct |
51 |
Correct |
63 ms |
158548 KB |
Output is correct |
52 |
Correct |
62 ms |
158544 KB |
Output is correct |
53 |
Correct |
70 ms |
158544 KB |
Output is correct |
54 |
Correct |
72 ms |
158544 KB |
Output is correct |
55 |
Correct |
67 ms |
158544 KB |
Output is correct |
56 |
Correct |
72 ms |
158340 KB |
Output is correct |
57 |
Correct |
72 ms |
158360 KB |
Output is correct |
58 |
Correct |
74 ms |
158544 KB |
Output is correct |
59 |
Correct |
84 ms |
158804 KB |
Output is correct |
60 |
Correct |
74 ms |
158804 KB |
Output is correct |
61 |
Correct |
76 ms |
159000 KB |
Output is correct |
62 |
Correct |
100 ms |
159572 KB |
Output is correct |
63 |
Correct |
83 ms |
159568 KB |
Output is correct |
64 |
Correct |
86 ms |
159556 KB |
Output is correct |
65 |
Correct |
68 ms |
158544 KB |
Output is correct |
66 |
Correct |
65 ms |
158396 KB |
Output is correct |
67 |
Correct |
68 ms |
158536 KB |
Output is correct |
68 |
Correct |
74 ms |
158356 KB |
Output is correct |
69 |
Correct |
72 ms |
158536 KB |
Output is correct |
70 |
Correct |
67 ms |
158404 KB |
Output is correct |
71 |
Correct |
71 ms |
158544 KB |
Output is correct |
72 |
Correct |
70 ms |
158680 KB |
Output is correct |
73 |
Correct |
73 ms |
158448 KB |
Output is correct |
74 |
Correct |
78 ms |
158800 KB |
Output is correct |
75 |
Correct |
76 ms |
158800 KB |
Output is correct |
76 |
Correct |
104 ms |
159044 KB |
Output is correct |
77 |
Correct |
99 ms |
159452 KB |
Output is correct |
78 |
Correct |
84 ms |
159636 KB |
Output is correct |
79 |
Correct |
94 ms |
159496 KB |
Output is correct |
80 |
Correct |
81 ms |
159404 KB |
Output is correct |
81 |
Correct |
91 ms |
159568 KB |
Output is correct |
82 |
Correct |
102 ms |
159572 KB |
Output is correct |
83 |
Correct |
76 ms |
158436 KB |
Output is correct |
84 |
Correct |
68 ms |
158544 KB |
Output is correct |
85 |
Correct |
71 ms |
158580 KB |
Output is correct |
86 |
Correct |
69 ms |
158544 KB |
Output is correct |
87 |
Correct |
73 ms |
158548 KB |
Output is correct |
88 |
Correct |
78 ms |
159140 KB |
Output is correct |
89 |
Correct |
78 ms |
159056 KB |
Output is correct |
90 |
Correct |
79 ms |
159056 KB |
Output is correct |
91 |
Correct |
102 ms |
159828 KB |
Output is correct |
92 |
Correct |
85 ms |
159904 KB |
Output is correct |
93 |
Correct |
98 ms |
159904 KB |
Output is correct |
94 |
Correct |
70 ms |
158600 KB |
Output is correct |
95 |
Correct |
71 ms |
158636 KB |
Output is correct |
96 |
Correct |
68 ms |
158548 KB |
Output is correct |
97 |
Correct |
70 ms |
158544 KB |
Output is correct |
98 |
Correct |
68 ms |
158548 KB |
Output is correct |
99 |
Correct |
73 ms |
158544 KB |
Output is correct |