# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1105096 | 2024-10-25T10:50:36 Z | manhlinh1501 | K blocks (IZhO14_blocks) | C++17 | 366 ms | 50464 KB |
#include<bits/stdc++.h> using namespace std; using i64 = long long; const int MAXN = 1e5 + 5; const int MAXK = 105; const int LOGN = 19; const int oo32 = 1e9 + 5; #define left ___left int N, K; int a[MAXN]; int RMQ[MAXN][LOGN]; int dp[MAXN][MAXK]; int left[MAXN]; int get_min(int l, int r) { int k = __lg(r - l + 1); return min(RMQ[l][k], RMQ[r - (1 << k) + 1][k]); } namespace solver { void solution() { dp[0][0] = 0; stack<int> S; int maxx = 0; for(int i = 1; i <= N; i++) dp[i][1] = (maxx = max(maxx, a[i])); for(int j = 2; j <= K; j++) { for(int i = 1; i <= N; i++) RMQ[i][0] = dp[i][j - 1]; for(int j = 1; j < LOGN; j++) { for(int i = 1; i + (1 << j) - 1 <= N; i++) RMQ[i][j] = min(RMQ[i][j - 1], RMQ[i + (1 << (j - 1))][j - 1]); } for(int i = 1; i <= N; i++) { if(left[i] < i) dp[i][j] = min(dp[i][j], get_min(left[i], i - 1) + a[i]); dp[i][j] = min(dp[i][j], min(dp[left[i] - 1][j], dp[left[i] - 1][j - 1] + a[i])); } } // for(int i = 1; i <= N; i++) { // for(int j = 1; j <= K; j++) // cerr << i << " " << j << " " << dp[i][j] << "\n"; // } cout << dp[N][K]; } } signed main() { #define task "code" if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> K; for(int i = 1; i <= N; i++) cin >> a[i]; for(int i = 1; i <= N; i++) { left[i] = i - 1; while(left[i] > 0 and a[left[i]] <= a[i]) left[i] = left[left[i]]; } for(int i = 1; i <= N; i++) left[i]++; memset(dp, 0x3f, sizeof dp); solver::solution(); return (0 ^ 0); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 43344 KB | Output is correct |
2 | Correct | 7 ms | 43344 KB | Output is correct |
3 | Correct | 6 ms | 43512 KB | Output is correct |
4 | Correct | 6 ms | 43344 KB | Output is correct |
5 | Correct | 5 ms | 43344 KB | Output is correct |
6 | Correct | 7 ms | 43344 KB | Output is correct |
7 | Correct | 6 ms | 43344 KB | Output is correct |
8 | Correct | 6 ms | 43344 KB | Output is correct |
9 | Correct | 7 ms | 43344 KB | Output is correct |
10 | Correct | 6 ms | 43488 KB | Output is correct |
11 | Correct | 7 ms | 43508 KB | Output is correct |
12 | Correct | 6 ms | 43344 KB | Output is correct |
13 | Correct | 6 ms | 43344 KB | Output is correct |
14 | Correct | 6 ms | 43344 KB | Output is correct |
15 | Correct | 7 ms | 43344 KB | Output is correct |
16 | Correct | 6 ms | 43344 KB | Output is correct |
17 | Correct | 7 ms | 43344 KB | Output is correct |
18 | Correct | 7 ms | 43344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 43516 KB | Output is correct |
2 | Correct | 5 ms | 43344 KB | Output is correct |
3 | Correct | 5 ms | 43344 KB | Output is correct |
4 | Correct | 6 ms | 43344 KB | Output is correct |
5 | Correct | 5 ms | 43344 KB | Output is correct |
6 | Correct | 6 ms | 43344 KB | Output is correct |
7 | Correct | 6 ms | 43512 KB | Output is correct |
8 | Correct | 6 ms | 43344 KB | Output is correct |
9 | Correct | 6 ms | 43344 KB | Output is correct |
10 | Correct | 7 ms | 43344 KB | Output is correct |
11 | Correct | 7 ms | 43344 KB | Output is correct |
12 | Correct | 6 ms | 43344 KB | Output is correct |
13 | Correct | 6 ms | 43344 KB | Output is correct |
14 | Correct | 6 ms | 43344 KB | Output is correct |
15 | Correct | 8 ms | 43344 KB | Output is correct |
16 | Correct | 6 ms | 43344 KB | Output is correct |
17 | Correct | 7 ms | 43360 KB | Output is correct |
18 | Correct | 6 ms | 43344 KB | Output is correct |
19 | Correct | 6 ms | 43344 KB | Output is correct |
20 | Correct | 6 ms | 43344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 43344 KB | Output is correct |
2 | Correct | 7 ms | 43344 KB | Output is correct |
3 | Correct | 6 ms | 43512 KB | Output is correct |
4 | Correct | 6 ms | 43344 KB | Output is correct |
5 | Correct | 5 ms | 43344 KB | Output is correct |
6 | Correct | 7 ms | 43344 KB | Output is correct |
7 | Correct | 6 ms | 43344 KB | Output is correct |
8 | Correct | 6 ms | 43344 KB | Output is correct |
9 | Correct | 7 ms | 43344 KB | Output is correct |
10 | Correct | 6 ms | 43488 KB | Output is correct |
11 | Correct | 7 ms | 43508 KB | Output is correct |
12 | Correct | 6 ms | 43344 KB | Output is correct |
13 | Correct | 6 ms | 43344 KB | Output is correct |
14 | Correct | 6 ms | 43344 KB | Output is correct |
15 | Correct | 7 ms | 43344 KB | Output is correct |
16 | Correct | 6 ms | 43344 KB | Output is correct |
17 | Correct | 7 ms | 43344 KB | Output is correct |
18 | Correct | 7 ms | 43344 KB | Output is correct |
19 | Correct | 6 ms | 43516 KB | Output is correct |
20 | Correct | 5 ms | 43344 KB | Output is correct |
21 | Correct | 5 ms | 43344 KB | Output is correct |
22 | Correct | 6 ms | 43344 KB | Output is correct |
23 | Correct | 5 ms | 43344 KB | Output is correct |
24 | Correct | 6 ms | 43344 KB | Output is correct |
25 | Correct | 6 ms | 43512 KB | Output is correct |
26 | Correct | 6 ms | 43344 KB | Output is correct |
27 | Correct | 6 ms | 43344 KB | Output is correct |
28 | Correct | 7 ms | 43344 KB | Output is correct |
29 | Correct | 7 ms | 43344 KB | Output is correct |
30 | Correct | 6 ms | 43344 KB | Output is correct |
31 | Correct | 6 ms | 43344 KB | Output is correct |
32 | Correct | 6 ms | 43344 KB | Output is correct |
33 | Correct | 8 ms | 43344 KB | Output is correct |
34 | Correct | 6 ms | 43344 KB | Output is correct |
35 | Correct | 7 ms | 43360 KB | Output is correct |
36 | Correct | 6 ms | 43344 KB | Output is correct |
37 | Correct | 6 ms | 43344 KB | Output is correct |
38 | Correct | 6 ms | 43344 KB | Output is correct |
39 | Correct | 6 ms | 43344 KB | Output is correct |
40 | Correct | 6 ms | 43552 KB | Output is correct |
41 | Correct | 7 ms | 43344 KB | Output is correct |
42 | Correct | 6 ms | 43552 KB | Output is correct |
43 | Correct | 6 ms | 43344 KB | Output is correct |
44 | Correct | 7 ms | 43344 KB | Output is correct |
45 | Correct | 6 ms | 43344 KB | Output is correct |
46 | Correct | 7 ms | 43344 KB | Output is correct |
47 | Correct | 5 ms | 43344 KB | Output is correct |
48 | Correct | 6 ms | 43344 KB | Output is correct |
49 | Correct | 5 ms | 43344 KB | Output is correct |
50 | Correct | 5 ms | 43344 KB | Output is correct |
51 | Correct | 5 ms | 43512 KB | Output is correct |
52 | Correct | 5 ms | 43344 KB | Output is correct |
53 | Correct | 5 ms | 43492 KB | Output is correct |
54 | Correct | 5 ms | 43344 KB | Output is correct |
55 | Correct | 5 ms | 43344 KB | Output is correct |
56 | Correct | 5 ms | 43564 KB | Output is correct |
57 | Correct | 5 ms | 43344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 43344 KB | Output is correct |
2 | Correct | 7 ms | 43344 KB | Output is correct |
3 | Correct | 6 ms | 43512 KB | Output is correct |
4 | Correct | 6 ms | 43344 KB | Output is correct |
5 | Correct | 5 ms | 43344 KB | Output is correct |
6 | Correct | 7 ms | 43344 KB | Output is correct |
7 | Correct | 6 ms | 43344 KB | Output is correct |
8 | Correct | 6 ms | 43344 KB | Output is correct |
9 | Correct | 7 ms | 43344 KB | Output is correct |
10 | Correct | 6 ms | 43488 KB | Output is correct |
11 | Correct | 7 ms | 43508 KB | Output is correct |
12 | Correct | 6 ms | 43344 KB | Output is correct |
13 | Correct | 6 ms | 43344 KB | Output is correct |
14 | Correct | 6 ms | 43344 KB | Output is correct |
15 | Correct | 7 ms | 43344 KB | Output is correct |
16 | Correct | 6 ms | 43344 KB | Output is correct |
17 | Correct | 7 ms | 43344 KB | Output is correct |
18 | Correct | 7 ms | 43344 KB | Output is correct |
19 | Correct | 6 ms | 43516 KB | Output is correct |
20 | Correct | 5 ms | 43344 KB | Output is correct |
21 | Correct | 5 ms | 43344 KB | Output is correct |
22 | Correct | 6 ms | 43344 KB | Output is correct |
23 | Correct | 5 ms | 43344 KB | Output is correct |
24 | Correct | 6 ms | 43344 KB | Output is correct |
25 | Correct | 6 ms | 43512 KB | Output is correct |
26 | Correct | 6 ms | 43344 KB | Output is correct |
27 | Correct | 6 ms | 43344 KB | Output is correct |
28 | Correct | 7 ms | 43344 KB | Output is correct |
29 | Correct | 7 ms | 43344 KB | Output is correct |
30 | Correct | 6 ms | 43344 KB | Output is correct |
31 | Correct | 6 ms | 43344 KB | Output is correct |
32 | Correct | 6 ms | 43344 KB | Output is correct |
33 | Correct | 8 ms | 43344 KB | Output is correct |
34 | Correct | 6 ms | 43344 KB | Output is correct |
35 | Correct | 7 ms | 43360 KB | Output is correct |
36 | Correct | 6 ms | 43344 KB | Output is correct |
37 | Correct | 6 ms | 43344 KB | Output is correct |
38 | Correct | 6 ms | 43344 KB | Output is correct |
39 | Correct | 6 ms | 43344 KB | Output is correct |
40 | Correct | 6 ms | 43552 KB | Output is correct |
41 | Correct | 7 ms | 43344 KB | Output is correct |
42 | Correct | 6 ms | 43552 KB | Output is correct |
43 | Correct | 6 ms | 43344 KB | Output is correct |
44 | Correct | 7 ms | 43344 KB | Output is correct |
45 | Correct | 6 ms | 43344 KB | Output is correct |
46 | Correct | 7 ms | 43344 KB | Output is correct |
47 | Correct | 5 ms | 43344 KB | Output is correct |
48 | Correct | 6 ms | 43344 KB | Output is correct |
49 | Correct | 5 ms | 43344 KB | Output is correct |
50 | Correct | 5 ms | 43344 KB | Output is correct |
51 | Correct | 5 ms | 43512 KB | Output is correct |
52 | Correct | 5 ms | 43344 KB | Output is correct |
53 | Correct | 5 ms | 43492 KB | Output is correct |
54 | Correct | 5 ms | 43344 KB | Output is correct |
55 | Correct | 5 ms | 43344 KB | Output is correct |
56 | Correct | 5 ms | 43564 KB | Output is correct |
57 | Correct | 5 ms | 43344 KB | Output is correct |
58 | Correct | 13 ms | 43600 KB | Output is correct |
59 | Correct | 9 ms | 44112 KB | Output is correct |
60 | Correct | 19 ms | 46232 KB | Output is correct |
61 | Correct | 112 ms | 46160 KB | Output is correct |
62 | Correct | 297 ms | 50256 KB | Output is correct |
63 | Correct | 20 ms | 50256 KB | Output is correct |
64 | Correct | 163 ms | 50256 KB | Output is correct |
65 | Correct | 5 ms | 43344 KB | Output is correct |
66 | Correct | 6 ms | 43536 KB | Output is correct |
67 | Correct | 5 ms | 43480 KB | Output is correct |
68 | Correct | 6 ms | 43516 KB | Output is correct |
69 | Correct | 6 ms | 43344 KB | Output is correct |
70 | Correct | 6 ms | 43580 KB | Output is correct |
71 | Correct | 29 ms | 43764 KB | Output is correct |
72 | Correct | 6 ms | 43600 KB | Output is correct |
73 | Correct | 12 ms | 43712 KB | Output is correct |
74 | Correct | 10 ms | 44112 KB | Output is correct |
75 | Correct | 19 ms | 46264 KB | Output is correct |
76 | Correct | 120 ms | 46256 KB | Output is correct |
77 | Correct | 366 ms | 50256 KB | Output is correct |
78 | Correct | 23 ms | 50256 KB | Output is correct |
79 | Correct | 176 ms | 50256 KB | Output is correct |
80 | Correct | 16 ms | 44624 KB | Output is correct |
81 | Correct | 51 ms | 50464 KB | Output is correct |
82 | Correct | 336 ms | 50364 KB | Output is correct |
83 | Correct | 6 ms | 43344 KB | Output is correct |
84 | Correct | 6 ms | 43344 KB | Output is correct |
85 | Correct | 31 ms | 43704 KB | Output is correct |
86 | Correct | 7 ms | 43600 KB | Output is correct |
87 | Correct | 16 ms | 43600 KB | Output is correct |
88 | Correct | 10 ms | 44144 KB | Output is correct |
89 | Correct | 21 ms | 46160 KB | Output is correct |
90 | Correct | 104 ms | 46160 KB | Output is correct |
91 | Correct | 366 ms | 50448 KB | Output is correct |
92 | Correct | 22 ms | 50256 KB | Output is correct |
93 | Correct | 152 ms | 50256 KB | Output is correct |
94 | Correct | 8 ms | 43600 KB | Output is correct |
95 | Correct | 30 ms | 43584 KB | Output is correct |
96 | Correct | 7 ms | 43344 KB | Output is correct |
97 | Correct | 6 ms | 43344 KB | Output is correct |
98 | Correct | 7 ms | 43344 KB | Output is correct |
99 | Correct | 7 ms | 43344 KB | Output is correct |