# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
258284 | 2020-08-05T16:02:40 Z | karma | K blocks (IZhO14_blocks) | C++14 | 10 ms | 1152 KB |
#include <bits/stdc++.h> #define pb emplace_back #define ll long long #define fi first #define se second #define mp make_pair //#define int int64_t using namespace std; const int N = int(1e6) + 7; const int inf = 1e9 + 1; typedef pair<ll, ll> pii; struct TNode { int x, y, ans; TNode() {x = y = ans = inf;} TNode(int x, int y): x(x), y(y) { ans = x + y; } void minimize(const TNode& o) { x = min(x, o.x); ans = min(ans, x + y); } } cur; int f[2][N], n, k, a[N]; vector<TNode> v; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #define Task "test" if(fopen(Task".inp", "r")) { freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout); } cin >> n >> k; for(int i = 1; i <= n; ++i) { cin >> a[i]; f[1][i] = max(f[1][i - 1], a[i]); } for(int i = 2; i <= k; ++i) { v.clear(); for(int j = i; j <= n; ++j) { cur = TNode(f[(i & 1) ^ 1][j - 1], a[j]); while(v.size() && v.back().y <= cur.y) { cur.minimize(v.back()); v.pop_back(); } if(v.size()) f[i & 1][j] = min(v.back().ans, cur.ans); else f[i & 1][j] = cur.ans; v.pb(cur); } } cout << f[k & 1][n]; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 256 KB | Output is correct |
3 | Correct | 0 ms | 384 KB | Output is correct |
4 | Correct | 0 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 0 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 0 ms | 384 KB | Output is correct |
9 | Correct | 0 ms | 384 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 0 ms | 384 KB | Output is correct |
12 | Correct | 1 ms | 384 KB | Output is correct |
13 | Incorrect | 0 ms | 384 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 0 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 0 ms | 360 KB | Output is correct |
7 | Correct | 0 ms | 384 KB | Output is correct |
8 | Correct | 0 ms | 384 KB | Output is correct |
9 | Correct | 0 ms | 384 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 0 ms | 384 KB | Output is correct |
12 | Correct | 1 ms | 384 KB | Output is correct |
13 | Correct | 1 ms | 384 KB | Output is correct |
14 | Correct | 0 ms | 384 KB | Output is correct |
15 | Correct | 1 ms | 384 KB | Output is correct |
16 | Incorrect | 0 ms | 384 KB | Output isn't correct |
17 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 512 KB | Output is correct |
2 | Correct | 6 ms | 1024 KB | Output is correct |
3 | Incorrect | 10 ms | 1152 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |