# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
238060 | 2020-06-09T20:54:49 Z | luciocf | K blocks (IZhO14_blocks) | C++14 | 79 ms | 19876 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; mn[j] = dp[j-1][j-1]; for (int i = j; i <= n; i++) { if (i != j) mn[i] = inf; while (stk.size() && stk.top().ff <= a[i]) { mn[i] = min(mn[i], mn[stk.top().ss]); stk.pop(); } 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 | 384 KB | Output is correct |
3 | Correct | 4 ms | 256 KB | Output is correct |
4 | Correct | 4 ms | 384 KB | Output is correct |
5 | Correct | 4 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 256 KB | Output is correct |
7 | Correct | 4 ms | 384 KB | Output is correct |
8 | Incorrect | 5 ms | 384 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |
# | 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 | 5 ms | 384 KB | Output is correct |
4 | Correct | 4 ms | 384 KB | Output is correct |
5 | Correct | 4 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 4 ms | 384 KB | Output is correct |
8 | Incorrect | 4 ms | 256 KB | Output isn't correct |
9 | 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 | 20 ms | 19712 KB | Output is correct |
3 | Correct | 23 ms | 19840 KB | Output is correct |
4 | Incorrect | 79 ms | 19876 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |