# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
753193 | 2023-06-04T19:34:24 Z | Olympia | K개의 묶음 (IZhO14_blocks) | C++17 | 1000 ms | 30448 KB |
#include <vector> #include <iostream> #include <cassert> #include <cmath> #include <map> #include <set> using namespace std; vector<int64_t> p; struct SegmentTree { vector<int64_t> orig; vector<int64_t> vec; vector<int64_t> lazy; const int64_t INF = 1e18; void push (int dum) { if (lazy[dum] == -1) { return; } lazy[2 * dum + 1] = lazy[dum]; lazy[2 * dum + 2] = lazy[dum]; vec[2 * dum + 1] = lazy[dum] + orig[2 * dum + 1]; vec[2 * dum + 2] = lazy[dum] + orig[2 * dum + 2]; lazy[dum] = -1; } void upd (int dum, int tl, int tr, int l, int r, int64_t x) { if (tl >= l and tr <= r) { lazy[dum] = x; vec[dum] = orig[dum] + x; return; } if (tl > r or l > tr) { return; } push(dum); upd(2 * dum + 1, tl, (tl + tr)/2, l, r, x); upd(2 * dum + 2, (tl + tr)/2 + 1, tr, l, r, x); vec[dum] = min(vec[2 * dum + 1], vec[2 * dum + 2]); } int64_t query (int dum, int tl, int tr, int l, int r) { if (tl >= l and tr <= r) { return vec[dum]; } if (tl > r or l > tr) { return INF; } push(dum); return min(query(2 * dum + 1, tl, (tl + tr)/2, l, r), query(2 * dum + 2, (tl + tr)/2 + 1, tr, l, r)); } void upd (int l, int r, int64_t x) { upd(0, 0, (int)vec.size()/2 - 1, l, r, x); } int64_t query (int l, int r) { return query(0, 0, (int)vec.size()/2 - 1, l, r); } void build (int dum, int tl, int tr) { if (tl == tr) { orig[dum] = p[tl]; return; } build(2 * dum + 1, tl, (tl + tr)/2); build(2 * dum + 2, (tl + tr)/2 + 1, tr); orig[dum] = min(orig[2 * dum + 1], orig[2 * dum + 2]); } SegmentTree () { while (__builtin_popcount(p.size()) != 1) { p.push_back(0); } int n = p.size(); orig.assign(2 * n, 0); lazy.assign(2 * n, -1); build(0, 0, n - 1); vec = orig; } }; struct SparseTable { vector<vector<int64_t>> dp; int64_t query (int l, int r) { int sz = log2(r - l + 1); return min(dp[l][sz], dp[r - (1 << sz) + 1][sz]); } SparseTable (vector<int64_t> a) { int n = a.size(); dp.resize(n); for (int i = 0; i < n; i++) { dp[i].resize(25); } for (int j = 0; j < dp[0].size(); j++) { for (int i = 0; i < n; i++) { if (j == 0) { dp[i][j] = a[i]; } else { dp[i][j] = min(dp[i][j - 1], dp[min(i + (1 << (j - 1)), (int)dp.size() - 1)][j - 1]); } } } } }; int main () { ios_base::sync_with_stdio(false); cin.tie(NULL); int N, K; cin >> N >> K; vector<int64_t> arr(N); for (int i = 0; i < N; i++) { cin >> arr[i]; } int64_t INF = 1e17; vector<int64_t> cur(N + 1); p.assign(N + 1, INF), cur.assign(N + 1, INF); for (int j = 1; j <= N; j++) { p[j] = ((j == 1) ? arr[0] : max(p[j - 1], arr[j - 1])); } for (int i = 0; i < arr.size(); i++) { arr[i] = -arr[i]; } SparseTable st_a(arr); for (int i = 0; i < arr.size(); i++) { arr[i] = -arr[i]; } for (int i = 2; i <= K; i++) { SegmentTree val; SparseTable st_p(p); for (int j = 1; j <= N; j++) { if (j == 1) { cur[j] = INF; int64_t myMax = 0; for (int l = j - 1; l >= 0; l--) { myMax = max(myMax, arr[l]); cur[j] = min(cur[j], p[l] + myMax); val.upd(l, l, myMax); } } else { cur[j] = INF; int64_t myMax = 0; int ind = -1; int l = 0; int r = j - 1; while (l != r) { int m = (l + r)/2; if (st_a.query(m, j - 1) == -arr[j - 1]) { r = m; } else { l = m + 1; } } ind = l; val.upd(ind, j - 1, arr[j - 1]); cur[j] = min(cur[j], arr[j - 1] + st_p.query(ind, j - 1)); cur[j] = min(cur[j], val.query(0, ind - 1)); } } swap(cur, p); } cout << p[N]; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 0 ms | 340 KB | Output is correct |
16 | Correct | 0 ms | 340 KB | Output is correct |
17 | Correct | 0 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 292 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 0 ms | 340 KB | Output is correct |
16 | Correct | 0 ms | 340 KB | Output is correct |
17 | Correct | 0 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 340 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 0 ms | 212 KB | Output is correct |
21 | Correct | 0 ms | 212 KB | Output is correct |
22 | Correct | 0 ms | 212 KB | Output is correct |
23 | Correct | 0 ms | 212 KB | Output is correct |
24 | Correct | 1 ms | 212 KB | Output is correct |
25 | Correct | 0 ms | 212 KB | Output is correct |
26 | Correct | 1 ms | 292 KB | Output is correct |
27 | Correct | 1 ms | 212 KB | Output is correct |
28 | Correct | 1 ms | 212 KB | Output is correct |
29 | Correct | 0 ms | 212 KB | Output is correct |
30 | Correct | 1 ms | 212 KB | Output is correct |
31 | Correct | 0 ms | 212 KB | Output is correct |
32 | Correct | 1 ms | 212 KB | Output is correct |
33 | Correct | 1 ms | 212 KB | Output is correct |
34 | Correct | 0 ms | 212 KB | Output is correct |
35 | Correct | 1 ms | 212 KB | Output is correct |
36 | Correct | 0 ms | 212 KB | Output is correct |
37 | Correct | 1 ms | 212 KB | Output is correct |
38 | Correct | 1 ms | 212 KB | Output is correct |
39 | Correct | 3 ms | 340 KB | Output is correct |
40 | Correct | 0 ms | 212 KB | Output is correct |
41 | Correct | 0 ms | 212 KB | Output is correct |
42 | Correct | 0 ms | 212 KB | Output is correct |
43 | Correct | 0 ms | 212 KB | Output is correct |
44 | Correct | 1 ms | 300 KB | Output is correct |
45 | Correct | 0 ms | 212 KB | Output is correct |
46 | Correct | 0 ms | 212 KB | Output is correct |
47 | Correct | 0 ms | 212 KB | Output is correct |
48 | Correct | 0 ms | 340 KB | Output is correct |
49 | Correct | 0 ms | 212 KB | Output is correct |
50 | Correct | 0 ms | 212 KB | Output is correct |
51 | Correct | 1 ms | 340 KB | Output is correct |
52 | Correct | 1 ms | 340 KB | Output is correct |
53 | Correct | 5 ms | 340 KB | Output is correct |
54 | Correct | 4 ms | 340 KB | Output is correct |
55 | Correct | 3 ms | 340 KB | Output is correct |
56 | Correct | 5 ms | 340 KB | Output is correct |
57 | Correct | 6 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 0 ms | 340 KB | Output is correct |
16 | Correct | 0 ms | 340 KB | Output is correct |
17 | Correct | 0 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 340 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 0 ms | 212 KB | Output is correct |
21 | Correct | 0 ms | 212 KB | Output is correct |
22 | Correct | 0 ms | 212 KB | Output is correct |
23 | Correct | 0 ms | 212 KB | Output is correct |
24 | Correct | 1 ms | 212 KB | Output is correct |
25 | Correct | 0 ms | 212 KB | Output is correct |
26 | Correct | 1 ms | 292 KB | Output is correct |
27 | Correct | 1 ms | 212 KB | Output is correct |
28 | Correct | 1 ms | 212 KB | Output is correct |
29 | Correct | 0 ms | 212 KB | Output is correct |
30 | Correct | 1 ms | 212 KB | Output is correct |
31 | Correct | 0 ms | 212 KB | Output is correct |
32 | Correct | 1 ms | 212 KB | Output is correct |
33 | Correct | 1 ms | 212 KB | Output is correct |
34 | Correct | 0 ms | 212 KB | Output is correct |
35 | Correct | 1 ms | 212 KB | Output is correct |
36 | Correct | 0 ms | 212 KB | Output is correct |
37 | Correct | 1 ms | 212 KB | Output is correct |
38 | Correct | 1 ms | 212 KB | Output is correct |
39 | Correct | 3 ms | 340 KB | Output is correct |
40 | Correct | 0 ms | 212 KB | Output is correct |
41 | Correct | 0 ms | 212 KB | Output is correct |
42 | Correct | 0 ms | 212 KB | Output is correct |
43 | Correct | 0 ms | 212 KB | Output is correct |
44 | Correct | 1 ms | 300 KB | Output is correct |
45 | Correct | 0 ms | 212 KB | Output is correct |
46 | Correct | 0 ms | 212 KB | Output is correct |
47 | Correct | 0 ms | 212 KB | Output is correct |
48 | Correct | 0 ms | 340 KB | Output is correct |
49 | Correct | 0 ms | 212 KB | Output is correct |
50 | Correct | 0 ms | 212 KB | Output is correct |
51 | Correct | 1 ms | 340 KB | Output is correct |
52 | Correct | 1 ms | 340 KB | Output is correct |
53 | Correct | 5 ms | 340 KB | Output is correct |
54 | Correct | 4 ms | 340 KB | Output is correct |
55 | Correct | 3 ms | 340 KB | Output is correct |
56 | Correct | 5 ms | 340 KB | Output is correct |
57 | Correct | 6 ms | 340 KB | Output is correct |
58 | Correct | 262 ms | 7560 KB | Output is correct |
59 | Correct | 20 ms | 11732 KB | Output is correct |
60 | Correct | 407 ms | 30448 KB | Output is correct |
61 | Execution timed out | 1082 ms | 30264 KB | Time limit exceeded |
62 | Halted | 0 ms | 0 KB | - |