# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
238075 | 2020-06-09T21:44:45 Z | luciocf | K blocks (IZhO14_blocks) | C++14 | 250 ms | 45288 KB |
#include <bits/stdc++.h> #define ff first #define ss second using namespace std; typedef pair<int, int> pii; const int maxn = 1e5+10; const int maxk = 110; const int inf = 1e9+10; int n, k; int a[maxn]; int mn[maxn]; int dp[maxn][maxk]; int main(void) { scanf("%d %d", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); dp[0][1] = inf, dp[1][1] = a[1]; for (int i = 2; i <= n; i++) dp[i][1] = max(a[i], dp[i-1][1]); for (int j = 2; j <= k; j++) { stack<pii> stk; for (int i = 0; i < j; i++) dp[i][j] = inf; for (int i = j; i <= n; i++) { mn[i] = dp[i-1][j-1]; dp[i][j] = inf; while (stk.size() && stk.top().ff <= a[i]) { mn[i] = min(mn[i], mn[stk.top().ss]); stk.pop(); } if (!stk.empty()) dp[i][j] = dp[stk.top().ss][j]; dp[i][j] = min(dp[i][j], a[i]+mn[i]); stk.push({a[i], i}); } } printf("%d\n", dp[n][k]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 256 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 4 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 4 ms | 384 KB | Output is correct |
9 | Correct | 4 ms | 384 KB | Output is correct |
10 | Correct | 4 ms | 384 KB | Output is correct |
11 | Correct | 4 ms | 384 KB | Output is correct |
12 | Correct | 5 ms | 384 KB | Output is correct |
13 | Correct | 4 ms | 384 KB | Output is correct |
14 | Correct | 5 ms | 384 KB | Output is correct |
15 | Correct | 5 ms | 384 KB | Output is correct |
16 | Correct | 5 ms | 384 KB | Output is correct |
17 | Correct | 4 ms | 384 KB | Output is correct |
18 | Correct | 5 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 256 KB | Output is correct |
2 | Correct | 4 ms | 256 KB | Output is correct |
3 | Correct | 4 ms | 256 KB | Output is correct |
4 | Correct | 4 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 432 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 4 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 4 ms | 384 KB | Output is correct |
12 | Correct | 4 ms | 384 KB | Output is correct |
13 | Correct | 5 ms | 384 KB | Output is correct |
14 | Correct | 4 ms | 384 KB | Output is correct |
15 | Correct | 4 ms | 384 KB | Output is correct |
16 | Correct | 5 ms | 384 KB | Output is correct |
17 | Correct | 4 ms | 384 KB | Output is correct |
18 | Correct | 4 ms | 384 KB | Output is correct |
19 | Correct | 5 ms | 384 KB | Output is correct |
20 | Correct | 5 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 4 ms | 384 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 5 ms | 384 KB | Output is correct |
12 | Correct | 4 ms | 384 KB | Output is correct |
13 | Correct | 5 ms | 384 KB | Output is correct |
14 | Correct | 5 ms | 384 KB | Output is correct |
15 | Correct | 5 ms | 384 KB | Output is correct |
16 | Correct | 5 ms | 384 KB | Output is correct |
17 | Correct | 5 ms | 384 KB | Output is correct |
18 | Correct | 5 ms | 384 KB | Output is correct |
19 | Correct | 5 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 4736 KB | Output is correct |
2 | Correct | 20 ms | 19584 KB | Output is correct |
3 | Correct | 23 ms | 19840 KB | Output is correct |
4 | Correct | 70 ms | 19840 KB | Output is correct |
5 | Correct | 208 ms | 44896 KB | Output is correct |
6 | Correct | 44 ms | 44792 KB | Output is correct |
7 | Correct | 129 ms | 44920 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 4 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 5 ms | 384 KB | Output is correct |
12 | Correct | 5 ms | 768 KB | Output is correct |
13 | Correct | 5 ms | 768 KB | Output is correct |
14 | Correct | 24 ms | 4736 KB | Output is correct |
15 | Correct | 8 ms | 4736 KB | Output is correct |
16 | Correct | 12 ms | 4736 KB | Output is correct |
17 | Correct | 20 ms | 19968 KB | Output is correct |
18 | Correct | 25 ms | 20096 KB | Output is correct |
19 | Correct | 75 ms | 20096 KB | Output is correct |
20 | Correct | 249 ms | 44920 KB | Output is correct |
21 | Correct | 45 ms | 44792 KB | Output is correct |
22 | Correct | 142 ms | 44800 KB | Output is correct |
23 | Correct | 41 ms | 44416 KB | Output is correct |
24 | Correct | 62 ms | 44824 KB | Output is correct |
25 | Correct | 247 ms | 44896 KB | Output is correct |
26 | Correct | 5 ms | 768 KB | Output is correct |
27 | Correct | 5 ms | 768 KB | Output is correct |
28 | Correct | 22 ms | 4864 KB | Output is correct |
29 | Correct | 9 ms | 4864 KB | Output is correct |
30 | Correct | 11 ms | 4864 KB | Output is correct |
31 | Correct | 21 ms | 19968 KB | Output is correct |
32 | Correct | 26 ms | 20352 KB | Output is correct |
33 | Correct | 72 ms | 20348 KB | Output is correct |
34 | Correct | 250 ms | 45288 KB | Output is correct |
35 | Correct | 42 ms | 45176 KB | Output is correct |
36 | Correct | 152 ms | 45188 KB | Output is correct |
37 | Correct | 9 ms | 4864 KB | Output is correct |
38 | Correct | 22 ms | 4736 KB | Output is correct |
39 | Correct | 5 ms | 768 KB | Output is correct |
40 | Correct | 5 ms | 768 KB | Output is correct |
41 | Correct | 5 ms | 384 KB | Output is correct |
42 | Correct | 4 ms | 384 KB | Output is correct |