# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
638342 | 2022-09-05T14:01:15 Z | nguyentunglam | K개의 묶음 (IZhO14_blocks) | C++14 | 196 ms | 44832 KB |
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define forin(i, a, b) for(int i = a; i <= b; i++) #define forde(i, a, b) for(int i = a; i >= b; i--) #define forv(a, b) for(auto & a : b) #define fi first #define se second #define ii pair<int, int> #define endl "\n" using namespace std; const int N = 1e5 + 10; int a[N], f[N][110]; int main() { #define task "" cin.tie(0) -> sync_with_stdio(0); if (fopen ("task.inp", "r")) { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); } if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } int n, k; cin >> n >> k; for(int i = 1; i <= n; i++) cin >> a[i]; memset(f, 127, sizeof(f)); f[0][0] = 0; for(int j = 1; j <= k; j++) { stack<pair<int, int>> s; for(int i = 1; i <= n; i++) { int g = f[i - 1][j - 1]; while (!s.empty() && a[s.top().fi] <= a[i]) { g = min(g, s.top().se); s.pop(); } f[i][j] = g + a[i]; if (!s.empty()) f[i][j] = min(f[i][j], f[s.top().fi][j]); s.push({i, g}); } } cout << f[n][k]; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 43348 KB | Output is correct |
2 | Correct | 17 ms | 43324 KB | Output is correct |
3 | Correct | 18 ms | 43340 KB | Output is correct |
4 | Correct | 18 ms | 43348 KB | Output is correct |
5 | Correct | 20 ms | 43316 KB | Output is correct |
6 | Correct | 17 ms | 43348 KB | Output is correct |
7 | Correct | 17 ms | 43308 KB | Output is correct |
8 | Correct | 17 ms | 43340 KB | Output is correct |
9 | Correct | 19 ms | 43348 KB | Output is correct |
10 | Correct | 20 ms | 43260 KB | Output is correct |
11 | Correct | 20 ms | 43344 KB | Output is correct |
12 | Correct | 19 ms | 43340 KB | Output is correct |
13 | Correct | 17 ms | 43276 KB | Output is correct |
14 | Correct | 17 ms | 43300 KB | Output is correct |
15 | Correct | 17 ms | 43348 KB | Output is correct |
16 | Correct | 18 ms | 43268 KB | Output is correct |
17 | Correct | 17 ms | 43348 KB | Output is correct |
18 | Correct | 19 ms | 43348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 43348 KB | Output is correct |
2 | Correct | 17 ms | 43348 KB | Output is correct |
3 | Correct | 17 ms | 43312 KB | Output is correct |
4 | Correct | 19 ms | 43356 KB | Output is correct |
5 | Correct | 18 ms | 43388 KB | Output is correct |
6 | Correct | 17 ms | 43348 KB | Output is correct |
7 | Correct | 20 ms | 43372 KB | Output is correct |
8 | Correct | 18 ms | 43336 KB | Output is correct |
9 | Correct | 18 ms | 43384 KB | Output is correct |
10 | Correct | 18 ms | 43356 KB | Output is correct |
11 | Correct | 18 ms | 43348 KB | Output is correct |
12 | Correct | 18 ms | 43348 KB | Output is correct |
13 | Correct | 20 ms | 43348 KB | Output is correct |
14 | Correct | 19 ms | 43300 KB | Output is correct |
15 | Correct | 18 ms | 43300 KB | Output is correct |
16 | Correct | 18 ms | 43284 KB | Output is correct |
17 | Correct | 22 ms | 43348 KB | Output is correct |
18 | Correct | 22 ms | 43368 KB | Output is correct |
19 | Correct | 18 ms | 43340 KB | Output is correct |
20 | Correct | 18 ms | 43336 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 43348 KB | Output is correct |
2 | Correct | 17 ms | 43324 KB | Output is correct |
3 | Correct | 18 ms | 43340 KB | Output is correct |
4 | Correct | 18 ms | 43348 KB | Output is correct |
5 | Correct | 20 ms | 43316 KB | Output is correct |
6 | Correct | 17 ms | 43348 KB | Output is correct |
7 | Correct | 17 ms | 43308 KB | Output is correct |
8 | Correct | 17 ms | 43340 KB | Output is correct |
9 | Correct | 19 ms | 43348 KB | Output is correct |
10 | Correct | 20 ms | 43260 KB | Output is correct |
11 | Correct | 20 ms | 43344 KB | Output is correct |
12 | Correct | 19 ms | 43340 KB | Output is correct |
13 | Correct | 17 ms | 43276 KB | Output is correct |
14 | Correct | 17 ms | 43300 KB | Output is correct |
15 | Correct | 17 ms | 43348 KB | Output is correct |
16 | Correct | 18 ms | 43268 KB | Output is correct |
17 | Correct | 17 ms | 43348 KB | Output is correct |
18 | Correct | 19 ms | 43348 KB | Output is correct |
19 | Correct | 23 ms | 43348 KB | Output is correct |
20 | Correct | 17 ms | 43348 KB | Output is correct |
21 | Correct | 17 ms | 43312 KB | Output is correct |
22 | Correct | 19 ms | 43356 KB | Output is correct |
23 | Correct | 18 ms | 43388 KB | Output is correct |
24 | Correct | 17 ms | 43348 KB | Output is correct |
25 | Correct | 20 ms | 43372 KB | Output is correct |
26 | Correct | 18 ms | 43336 KB | Output is correct |
27 | Correct | 18 ms | 43384 KB | Output is correct |
28 | Correct | 18 ms | 43356 KB | Output is correct |
29 | Correct | 18 ms | 43348 KB | Output is correct |
30 | Correct | 18 ms | 43348 KB | Output is correct |
31 | Correct | 20 ms | 43348 KB | Output is correct |
32 | Correct | 19 ms | 43300 KB | Output is correct |
33 | Correct | 18 ms | 43300 KB | Output is correct |
34 | Correct | 18 ms | 43284 KB | Output is correct |
35 | Correct | 22 ms | 43348 KB | Output is correct |
36 | Correct | 22 ms | 43368 KB | Output is correct |
37 | Correct | 18 ms | 43340 KB | Output is correct |
38 | Correct | 18 ms | 43336 KB | Output is correct |
39 | Correct | 18 ms | 43348 KB | Output is correct |
40 | Correct | 17 ms | 43280 KB | Output is correct |
41 | Correct | 17 ms | 43276 KB | Output is correct |
42 | Correct | 19 ms | 43340 KB | Output is correct |
43 | Correct | 18 ms | 43344 KB | Output is correct |
44 | Correct | 18 ms | 43332 KB | Output is correct |
45 | Correct | 18 ms | 43292 KB | Output is correct |
46 | Correct | 19 ms | 43376 KB | Output is correct |
47 | Correct | 18 ms | 43344 KB | Output is correct |
48 | Correct | 18 ms | 43340 KB | Output is correct |
49 | Correct | 19 ms | 43340 KB | Output is correct |
50 | Correct | 19 ms | 43384 KB | Output is correct |
51 | Correct | 22 ms | 43344 KB | Output is correct |
52 | Correct | 19 ms | 43336 KB | Output is correct |
53 | Correct | 17 ms | 43348 KB | Output is correct |
54 | Correct | 17 ms | 43280 KB | Output is correct |
55 | Correct | 18 ms | 43344 KB | Output is correct |
56 | Correct | 17 ms | 43348 KB | Output is correct |
57 | Correct | 18 ms | 43348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 43348 KB | Output is correct |
2 | Correct | 17 ms | 43324 KB | Output is correct |
3 | Correct | 18 ms | 43340 KB | Output is correct |
4 | Correct | 18 ms | 43348 KB | Output is correct |
5 | Correct | 20 ms | 43316 KB | Output is correct |
6 | Correct | 17 ms | 43348 KB | Output is correct |
7 | Correct | 17 ms | 43308 KB | Output is correct |
8 | Correct | 17 ms | 43340 KB | Output is correct |
9 | Correct | 19 ms | 43348 KB | Output is correct |
10 | Correct | 20 ms | 43260 KB | Output is correct |
11 | Correct | 20 ms | 43344 KB | Output is correct |
12 | Correct | 19 ms | 43340 KB | Output is correct |
13 | Correct | 17 ms | 43276 KB | Output is correct |
14 | Correct | 17 ms | 43300 KB | Output is correct |
15 | Correct | 17 ms | 43348 KB | Output is correct |
16 | Correct | 18 ms | 43268 KB | Output is correct |
17 | Correct | 17 ms | 43348 KB | Output is correct |
18 | Correct | 19 ms | 43348 KB | Output is correct |
19 | Correct | 23 ms | 43348 KB | Output is correct |
20 | Correct | 17 ms | 43348 KB | Output is correct |
21 | Correct | 17 ms | 43312 KB | Output is correct |
22 | Correct | 19 ms | 43356 KB | Output is correct |
23 | Correct | 18 ms | 43388 KB | Output is correct |
24 | Correct | 17 ms | 43348 KB | Output is correct |
25 | Correct | 20 ms | 43372 KB | Output is correct |
26 | Correct | 18 ms | 43336 KB | Output is correct |
27 | Correct | 18 ms | 43384 KB | Output is correct |
28 | Correct | 18 ms | 43356 KB | Output is correct |
29 | Correct | 18 ms | 43348 KB | Output is correct |
30 | Correct | 18 ms | 43348 KB | Output is correct |
31 | Correct | 20 ms | 43348 KB | Output is correct |
32 | Correct | 19 ms | 43300 KB | Output is correct |
33 | Correct | 18 ms | 43300 KB | Output is correct |
34 | Correct | 18 ms | 43284 KB | Output is correct |
35 | Correct | 22 ms | 43348 KB | Output is correct |
36 | Correct | 22 ms | 43368 KB | Output is correct |
37 | Correct | 18 ms | 43340 KB | Output is correct |
38 | Correct | 18 ms | 43336 KB | Output is correct |
39 | Correct | 18 ms | 43348 KB | Output is correct |
40 | Correct | 17 ms | 43280 KB | Output is correct |
41 | Correct | 17 ms | 43276 KB | Output is correct |
42 | Correct | 19 ms | 43340 KB | Output is correct |
43 | Correct | 18 ms | 43344 KB | Output is correct |
44 | Correct | 18 ms | 43332 KB | Output is correct |
45 | Correct | 18 ms | 43292 KB | Output is correct |
46 | Correct | 19 ms | 43376 KB | Output is correct |
47 | Correct | 18 ms | 43344 KB | Output is correct |
48 | Correct | 18 ms | 43340 KB | Output is correct |
49 | Correct | 19 ms | 43340 KB | Output is correct |
50 | Correct | 19 ms | 43384 KB | Output is correct |
51 | Correct | 22 ms | 43344 KB | Output is correct |
52 | Correct | 19 ms | 43336 KB | Output is correct |
53 | Correct | 17 ms | 43348 KB | Output is correct |
54 | Correct | 17 ms | 43280 KB | Output is correct |
55 | Correct | 18 ms | 43344 KB | Output is correct |
56 | Correct | 17 ms | 43348 KB | Output is correct |
57 | Correct | 18 ms | 43348 KB | Output is correct |
58 | Correct | 22 ms | 43460 KB | Output is correct |
59 | Correct | 22 ms | 43836 KB | Output is correct |
60 | Correct | 26 ms | 43828 KB | Output is correct |
61 | Correct | 64 ms | 43844 KB | Output is correct |
62 | Correct | 188 ms | 44444 KB | Output is correct |
63 | Correct | 31 ms | 44364 KB | Output is correct |
64 | Correct | 107 ms | 44576 KB | Output is correct |
65 | Correct | 18 ms | 43340 KB | Output is correct |
66 | Correct | 18 ms | 43308 KB | Output is correct |
67 | Correct | 18 ms | 43348 KB | Output is correct |
68 | Correct | 17 ms | 43336 KB | Output is correct |
69 | Correct | 18 ms | 43348 KB | Output is correct |
70 | Correct | 20 ms | 43348 KB | Output is correct |
71 | Correct | 32 ms | 43476 KB | Output is correct |
72 | Correct | 19 ms | 43400 KB | Output is correct |
73 | Correct | 23 ms | 43452 KB | Output is correct |
74 | Correct | 22 ms | 43860 KB | Output is correct |
75 | Correct | 26 ms | 43852 KB | Output is correct |
76 | Correct | 71 ms | 43840 KB | Output is correct |
77 | Correct | 196 ms | 44440 KB | Output is correct |
78 | Correct | 30 ms | 44364 KB | Output is correct |
79 | Correct | 100 ms | 44436 KB | Output is correct |
80 | Correct | 28 ms | 44340 KB | Output is correct |
81 | Correct | 45 ms | 44364 KB | Output is correct |
82 | Correct | 190 ms | 44404 KB | Output is correct |
83 | Correct | 18 ms | 43376 KB | Output is correct |
84 | Correct | 18 ms | 43288 KB | Output is correct |
85 | Correct | 31 ms | 43476 KB | Output is correct |
86 | Correct | 18 ms | 43476 KB | Output is correct |
87 | Correct | 21 ms | 43476 KB | Output is correct |
88 | Correct | 22 ms | 43916 KB | Output is correct |
89 | Correct | 25 ms | 43992 KB | Output is correct |
90 | Correct | 66 ms | 44020 KB | Output is correct |
91 | Correct | 177 ms | 44732 KB | Output is correct |
92 | Correct | 30 ms | 44724 KB | Output is correct |
93 | Correct | 96 ms | 44832 KB | Output is correct |
94 | Correct | 20 ms | 43408 KB | Output is correct |
95 | Correct | 29 ms | 43476 KB | Output is correct |
96 | Correct | 18 ms | 43344 KB | Output is correct |
97 | Correct | 18 ms | 43344 KB | Output is correct |
98 | Correct | 18 ms | 43348 KB | Output is correct |
99 | Correct | 18 ms | 43244 KB | Output is correct |