# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28888 | 2017-07-17T12:07:40 Z | ulna | K blocks (IZhO14_blocks) | C++11 | 213 ms | 64112 KB |
#include <bits/stdc++.h> using namespace std; // why am I so weak int n, k; int a[100055]; int dp[155][100055]; typedef pair<int, int> P; #define ft first #define sd second P p[100055]; int main() { scanf("%d %d", &n, &k); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } memset(dp, 63, sizeof(dp)); dp[0][0] = 0; for (int i = 1; i <= k; i++) { stack<P> sta; sta.push(P(0x3f3f3f3f, 0x3f3f3f3f)); for (int j = 1; j <= n; j++) { int low = dp[i - 1][j - 1]; while (!sta.empty() && sta.top().ft <= a[j]) { low = min(low, sta.top().sd); sta.pop(); } dp[i][j] = min(sta.top().ft + sta.top().sd, a[j] + low); if (sta.top().ft + sta.top().sd > a[j] + low) { sta.push(P(a[j], low)); } } } printf("%d\n", dp[k][n]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 63772 KB | Output is correct |
2 | Correct | 3 ms | 63772 KB | Output is correct |
3 | Correct | 3 ms | 63772 KB | Output is correct |
4 | Correct | 3 ms | 63772 KB | Output is correct |
5 | Correct | 0 ms | 63772 KB | Output is correct |
6 | Correct | 9 ms | 63772 KB | Output is correct |
7 | Correct | 9 ms | 63772 KB | Output is correct |
8 | Correct | 3 ms | 63772 KB | Output is correct |
9 | Correct | 6 ms | 63772 KB | Output is correct |
10 | Correct | 3 ms | 63772 KB | Output is correct |
11 | Correct | 3 ms | 63772 KB | Output is correct |
12 | Correct | 3 ms | 63772 KB | Output is correct |
13 | Correct | 6 ms | 63772 KB | Output is correct |
14 | Correct | 0 ms | 63772 KB | Output is correct |
15 | Correct | 6 ms | 63772 KB | Output is correct |
16 | Correct | 3 ms | 63772 KB | Output is correct |
17 | Correct | 3 ms | 63772 KB | Output is correct |
18 | Correct | 0 ms | 63772 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 63772 KB | Output is correct |
2 | Correct | 0 ms | 63772 KB | Output is correct |
3 | Correct | 3 ms | 63772 KB | Output is correct |
4 | Correct | 0 ms | 63772 KB | Output is correct |
5 | Correct | 3 ms | 63772 KB | Output is correct |
6 | Correct | 3 ms | 63772 KB | Output is correct |
7 | Correct | 9 ms | 63772 KB | Output is correct |
8 | Correct | 6 ms | 63772 KB | Output is correct |
9 | Correct | 9 ms | 63772 KB | Output is correct |
10 | Correct | 3 ms | 63772 KB | Output is correct |
11 | Correct | 6 ms | 63772 KB | Output is correct |
12 | Correct | 3 ms | 63772 KB | Output is correct |
13 | Correct | 13 ms | 63772 KB | Output is correct |
14 | Correct | 0 ms | 63772 KB | Output is correct |
15 | Correct | 6 ms | 63772 KB | Output is correct |
16 | Correct | 3 ms | 63772 KB | Output is correct |
17 | Correct | 3 ms | 63772 KB | Output is correct |
18 | Correct | 9 ms | 63772 KB | Output is correct |
19 | Correct | 9 ms | 63772 KB | Output is correct |
20 | Correct | 3 ms | 63772 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 63772 KB | Output is correct |
2 | Correct | 6 ms | 63772 KB | Output is correct |
3 | Correct | 0 ms | 63772 KB | Output is correct |
4 | Correct | 3 ms | 63772 KB | Output is correct |
5 | Correct | 6 ms | 63772 KB | Output is correct |
6 | Correct | 3 ms | 63772 KB | Output is correct |
7 | Correct | 0 ms | 63772 KB | Output is correct |
8 | Correct | 0 ms | 63772 KB | Output is correct |
9 | Correct | 6 ms | 63772 KB | Output is correct |
10 | Correct | 6 ms | 63772 KB | Output is correct |
11 | Correct | 6 ms | 63772 KB | Output is correct |
12 | Correct | 3 ms | 63772 KB | Output is correct |
13 | Correct | 9 ms | 63772 KB | Output is correct |
14 | Correct | 9 ms | 63772 KB | Output is correct |
15 | Correct | 3 ms | 63772 KB | Output is correct |
16 | Correct | 0 ms | 63772 KB | Output is correct |
17 | Correct | 3 ms | 63772 KB | Output is correct |
18 | Correct | 0 ms | 63772 KB | Output is correct |
19 | Correct | 0 ms | 63772 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 63772 KB | Output is correct |
2 | Correct | 13 ms | 63772 KB | Output is correct |
3 | Correct | 16 ms | 63772 KB | Output is correct |
4 | Correct | 43 ms | 63772 KB | Output is correct |
5 | Correct | 146 ms | 63772 KB | Output is correct |
6 | Correct | 16 ms | 63772 KB | Output is correct |
7 | Correct | 76 ms | 63772 KB | Output is correct |
8 | Correct | 6 ms | 63772 KB | Output is correct |
9 | Correct | 0 ms | 63772 KB | Output is correct |
10 | Correct | 6 ms | 63772 KB | Output is correct |
11 | Correct | 3 ms | 63772 KB | Output is correct |
12 | Correct | 3 ms | 63772 KB | Output is correct |
13 | Correct | 3 ms | 63772 KB | Output is correct |
14 | Correct | 16 ms | 63772 KB | Output is correct |
15 | Correct | 6 ms | 63772 KB | Output is correct |
16 | Correct | 13 ms | 63772 KB | Output is correct |
17 | Correct | 9 ms | 63772 KB | Output is correct |
18 | Correct | 26 ms | 63772 KB | Output is correct |
19 | Correct | 43 ms | 63772 KB | Output is correct |
20 | Correct | 119 ms | 63772 KB | Output is correct |
21 | Correct | 19 ms | 63772 KB | Output is correct |
22 | Correct | 59 ms | 63772 KB | Output is correct |
23 | Correct | 23 ms | 63772 KB | Output is correct |
24 | Correct | 26 ms | 63772 KB | Output is correct |
25 | Correct | 106 ms | 63772 KB | Output is correct |
26 | Correct | 3 ms | 63772 KB | Output is correct |
27 | Correct | 9 ms | 63772 KB | Output is correct |
28 | Correct | 26 ms | 63772 KB | Output is correct |
29 | Correct | 3 ms | 63772 KB | Output is correct |
30 | Correct | 13 ms | 63772 KB | Output is correct |
31 | Correct | 9 ms | 63772 KB | Output is correct |
32 | Correct | 13 ms | 63904 KB | Output is correct |
33 | Correct | 69 ms | 63980 KB | Output is correct |
34 | Correct | 213 ms | 64112 KB | Output is correct |
35 | Correct | 19 ms | 64032 KB | Output is correct |
36 | Correct | 113 ms | 64112 KB | Output is correct |
37 | Correct | 3 ms | 63772 KB | Output is correct |
38 | Correct | 13 ms | 63772 KB | Output is correct |
39 | Correct | 6 ms | 63772 KB | Output is correct |
40 | Correct | 0 ms | 63772 KB | Output is correct |
41 | Correct | 9 ms | 63772 KB | Output is correct |
42 | Correct | 0 ms | 63772 KB | Output is correct |