# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
238058 | 2020-06-09T20:49:25 Z | luciocf | K blocks (IZhO14_blocks) | C++14 | 71 ms | 20224 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] = inf; while (stk.size() && stk.top().ff <= a[i]) { mn[i] = min(mn[i], mn[stk.top().ss]); stk.pop(); } mn[i] = min(mn[i], dp[i-1][j-1]); stk.push({a[i], i}); if (a[i] <= a[i-1]) dp[i][j] = min(a[i]+mn[i], dp[i-1][j]); else dp[i][j] = a[i]+mn[i]; } } printf("%d\n", dp[n][k]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 256 KB | Output is correct |
3 | Correct | 5 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 | 4 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 | 5 ms | 384 KB | Output is correct |
11 | Correct | 5 ms | 384 KB | Output is correct |
12 | Correct | 5 ms | 256 KB | Output is correct |
13 | Incorrect | 5 ms | 384 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 512 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 4 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 | 4 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 512 KB | Output is correct |
10 | Correct | 4 ms | 384 KB | Output is correct |
11 | Correct | 5 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 | Incorrect | 5 ms | 384 KB | Output isn't correct |
19 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 4736 KB | Output is correct |
2 | Correct | 18 ms | 19968 KB | Output is correct |
3 | Correct | 23 ms | 20224 KB | Output is correct |
4 | Incorrect | 71 ms | 20096 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |