# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
671808 | 2022-12-14T02:49:44 Z | Alihan_8 | K개의 묶음 (IZhO14_blocks) | C++17 | 290 ms | 160932 KB |
#include <bits/stdc++.h> // include <ext/pb_ds/assoc_container.hpp> // include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define all(x) x.begin(), x.end() #define pb push_back // define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> #define mpr make_pair #define ln '\n' void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);} #define int long long signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; const int inf = 1e15; vector <int> p(n+1, inf); for ( int i = 1; i <= n; i++ ) cin >> p[i]; vector <vector<int>> dp(k+1, vector <int> (n+1, inf)), f(k+1, vector <int> (n+1, inf)); dp[0][0] = 0; auto chmin = [&](int &l, int r){l = min(l, r);}; for ( int i = 1; i <= k; i++ ){ stack <int> st; st.push(0); int Mx = -inf; for ( int j = 1; j <= n; j++ ){ Mx = max(Mx, p[j]); if ( i == 1 ) dp[i][j] = f[i][j] = Mx; while ( p[st.top()] <= p[j] ){ int last = st.top(); st.pop(); chmin(f[i-1][st.top()], f[i-1][last]); } chmin(dp[i][j], dp[i][st.top()]); chmin(dp[i][j], f[i-1][st.top()]+p[j]); f[i][j] = dp[i][j]; st.push(j); } } cout << dp[k].back(); cout << '\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 | 0 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 | 212 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 324 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 212 KB | Output is correct |
18 | Correct | 1 ms | 312 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 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 | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 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 | 324 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 324 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 320 KB | Output is correct |
20 | Correct | 0 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 | 0 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 | 212 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 324 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 212 KB | Output is correct |
18 | Correct | 1 ms | 312 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 1 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 | 0 ms | 212 KB | Output is correct |
25 | Correct | 0 ms | 212 KB | Output is correct |
26 | Correct | 0 ms | 212 KB | Output is correct |
27 | Correct | 0 ms | 212 KB | Output is correct |
28 | Correct | 0 ms | 212 KB | Output is correct |
29 | Correct | 0 ms | 212 KB | Output is correct |
30 | Correct | 0 ms | 324 KB | Output is correct |
31 | Correct | 0 ms | 212 KB | Output is correct |
32 | Correct | 1 ms | 212 KB | Output is correct |
33 | Correct | 0 ms | 212 KB | Output is correct |
34 | Correct | 0 ms | 212 KB | Output is correct |
35 | Correct | 1 ms | 324 KB | Output is correct |
36 | Correct | 0 ms | 212 KB | Output is correct |
37 | Correct | 0 ms | 320 KB | Output is correct |
38 | Correct | 0 ms | 212 KB | Output is correct |
39 | Correct | 1 ms | 340 KB | Output is correct |
40 | Correct | 0 ms | 212 KB | Output is correct |
41 | Correct | 0 ms | 316 KB | Output is correct |
42 | Correct | 0 ms | 212 KB | Output is correct |
43 | Correct | 1 ms | 324 KB | Output is correct |
44 | Correct | 1 ms | 324 KB | Output is correct |
45 | Correct | 1 ms | 212 KB | Output is correct |
46 | Correct | 1 ms | 212 KB | Output is correct |
47 | Correct | 1 ms | 212 KB | Output is correct |
48 | Correct | 0 ms | 212 KB | Output is correct |
49 | Correct | 1 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 | 1 ms | 468 KB | Output is correct |
54 | Correct | 1 ms | 468 KB | Output is correct |
55 | Correct | 1 ms | 340 KB | Output is correct |
56 | Correct | 1 ms | 448 KB | Output is correct |
57 | Correct | 1 ms | 468 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 | 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 | 212 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 324 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 212 KB | Output is correct |
18 | Correct | 1 ms | 312 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 1 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 | 0 ms | 212 KB | Output is correct |
25 | Correct | 0 ms | 212 KB | Output is correct |
26 | Correct | 0 ms | 212 KB | Output is correct |
27 | Correct | 0 ms | 212 KB | Output is correct |
28 | Correct | 0 ms | 212 KB | Output is correct |
29 | Correct | 0 ms | 212 KB | Output is correct |
30 | Correct | 0 ms | 324 KB | Output is correct |
31 | Correct | 0 ms | 212 KB | Output is correct |
32 | Correct | 1 ms | 212 KB | Output is correct |
33 | Correct | 0 ms | 212 KB | Output is correct |
34 | Correct | 0 ms | 212 KB | Output is correct |
35 | Correct | 1 ms | 324 KB | Output is correct |
36 | Correct | 0 ms | 212 KB | Output is correct |
37 | Correct | 0 ms | 320 KB | Output is correct |
38 | Correct | 0 ms | 212 KB | Output is correct |
39 | Correct | 1 ms | 340 KB | Output is correct |
40 | Correct | 0 ms | 212 KB | Output is correct |
41 | Correct | 0 ms | 316 KB | Output is correct |
42 | Correct | 0 ms | 212 KB | Output is correct |
43 | Correct | 1 ms | 324 KB | Output is correct |
44 | Correct | 1 ms | 324 KB | Output is correct |
45 | Correct | 1 ms | 212 KB | Output is correct |
46 | Correct | 1 ms | 212 KB | Output is correct |
47 | Correct | 1 ms | 212 KB | Output is correct |
48 | Correct | 0 ms | 212 KB | Output is correct |
49 | Correct | 1 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 | 1 ms | 468 KB | Output is correct |
54 | Correct | 1 ms | 468 KB | Output is correct |
55 | Correct | 1 ms | 340 KB | Output is correct |
56 | Correct | 1 ms | 448 KB | Output is correct |
57 | Correct | 1 ms | 468 KB | Output is correct |
58 | Correct | 8 ms | 4564 KB | Output is correct |
59 | Correct | 6 ms | 2688 KB | Output is correct |
60 | Correct | 14 ms | 6896 KB | Output is correct |
61 | Correct | 92 ms | 55032 KB | Output is correct |
62 | Correct | 264 ms | 160928 KB | Output is correct |
63 | Correct | 19 ms | 8772 KB | Output is correct |
64 | Correct | 125 ms | 74552 KB | Output is correct |
65 | Correct | 1 ms | 316 KB | Output is correct |
66 | Correct | 1 ms | 340 KB | Output is correct |
67 | Correct | 1 ms | 340 KB | Output is correct |
68 | Correct | 1 ms | 324 KB | Output is correct |
69 | Correct | 1 ms | 328 KB | Output is correct |
70 | Correct | 1 ms | 468 KB | Output is correct |
71 | Correct | 30 ms | 16340 KB | Output is correct |
72 | Correct | 2 ms | 980 KB | Output is correct |
73 | Correct | 8 ms | 4564 KB | Output is correct |
74 | Correct | 6 ms | 2712 KB | Output is correct |
75 | Correct | 14 ms | 6776 KB | Output is correct |
76 | Correct | 101 ms | 54884 KB | Output is correct |
77 | Correct | 287 ms | 160828 KB | Output is correct |
78 | Correct | 18 ms | 8760 KB | Output is correct |
79 | Correct | 139 ms | 74656 KB | Output is correct |
80 | Correct | 13 ms | 5572 KB | Output is correct |
81 | Correct | 42 ms | 19776 KB | Output is correct |
82 | Correct | 290 ms | 160828 KB | Output is correct |
83 | Correct | 1 ms | 340 KB | Output is correct |
84 | Correct | 1 ms | 468 KB | Output is correct |
85 | Correct | 27 ms | 16340 KB | Output is correct |
86 | Correct | 2 ms | 980 KB | Output is correct |
87 | Correct | 8 ms | 4560 KB | Output is correct |
88 | Correct | 6 ms | 2680 KB | Output is correct |
89 | Correct | 13 ms | 6896 KB | Output is correct |
90 | Correct | 90 ms | 54960 KB | Output is correct |
91 | Correct | 257 ms | 160932 KB | Output is correct |
92 | Correct | 18 ms | 8768 KB | Output is correct |
93 | Correct | 125 ms | 74668 KB | Output is correct |
94 | Correct | 2 ms | 980 KB | Output is correct |
95 | Correct | 27 ms | 16328 KB | Output is correct |
96 | Correct | 1 ms | 468 KB | Output is correct |
97 | Correct | 1 ms | 340 KB | Output is correct |
98 | Correct | 0 ms | 212 KB | Output is correct |
99 | Correct | 1 ms | 212 KB | Output is correct |