# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
201178 | 2020-02-09T15:33:05 Z | quocnguyen1012 | K개의 묶음 (IZhO14_blocks) | C++14 | 365 ms | 43924 KB |
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back using namespace std; typedef long long ll; const int maxn = 1e5 + 5; int a[maxn], f[maxn][105]; int N, K; signed main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("A.INP", "r")){ freopen("A.INP", "r", stdin); freopen("A.OUT", "w", stdout); } cin >> N >> K; fill_n(&f[0][0], maxn * 105, 1e9 + 5); int mx = 0; for (int i = 1; i <= N; ++i){ cin >> a[i]; mx = max(mx, a[i]); f[i][1] = mx; } for (int j = 2; j <= K; ++j){ vector<pair<pair<int, int>, int>> vec; for (int i = 1; i <= N; ++i){ int v = f[i - 1][j - 1]; while (vec.size() && vec.back().fi.fi <= a[i]){ v = min(v, vec.back().fi.se); vec.pop_back(); } int val = v + a[i]; if (vec.size()){ val = min(val, vec.back().se); } f[i][j] = val; vec.pb(mp(mp(a[i], v), val)); } } cout << f[N][K]; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 31 ms | 41464 KB | Output is correct |
2 | Correct | 32 ms | 41464 KB | Output is correct |
3 | Correct | 30 ms | 41464 KB | Output is correct |
4 | Correct | 32 ms | 41464 KB | Output is correct |
5 | Correct | 31 ms | 41464 KB | Output is correct |
6 | Correct | 31 ms | 41464 KB | Output is correct |
7 | Correct | 31 ms | 41464 KB | Output is correct |
8 | Correct | 34 ms | 41592 KB | Output is correct |
9 | Correct | 30 ms | 41464 KB | Output is correct |
10 | Correct | 31 ms | 41464 KB | Output is correct |
11 | Correct | 31 ms | 41464 KB | Output is correct |
12 | Correct | 31 ms | 41464 KB | Output is correct |
13 | Correct | 32 ms | 41464 KB | Output is correct |
14 | Correct | 33 ms | 41464 KB | Output is correct |
15 | Correct | 31 ms | 41464 KB | Output is correct |
16 | Correct | 31 ms | 41464 KB | Output is correct |
17 | Correct | 34 ms | 41464 KB | Output is correct |
18 | Correct | 31 ms | 41464 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 31 ms | 41464 KB | Output is correct |
2 | Correct | 31 ms | 41464 KB | Output is correct |
3 | Correct | 34 ms | 41464 KB | Output is correct |
4 | Correct | 32 ms | 41468 KB | Output is correct |
5 | Correct | 31 ms | 41464 KB | Output is correct |
6 | Correct | 31 ms | 41464 KB | Output is correct |
7 | Correct | 32 ms | 41468 KB | Output is correct |
8 | Correct | 31 ms | 41464 KB | Output is correct |
9 | Correct | 33 ms | 41464 KB | Output is correct |
10 | Correct | 32 ms | 41464 KB | Output is correct |
11 | Correct | 31 ms | 41464 KB | Output is correct |
12 | Correct | 31 ms | 41464 KB | Output is correct |
13 | Correct | 32 ms | 41464 KB | Output is correct |
14 | Correct | 31 ms | 41440 KB | Output is correct |
15 | Correct | 31 ms | 41464 KB | Output is correct |
16 | Correct | 34 ms | 41464 KB | Output is correct |
17 | Correct | 31 ms | 41464 KB | Output is correct |
18 | Correct | 46 ms | 41464 KB | Output is correct |
19 | Correct | 31 ms | 41464 KB | Output is correct |
20 | Correct | 32 ms | 41464 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 31 ms | 41464 KB | Output is correct |
2 | Correct | 35 ms | 41464 KB | Output is correct |
3 | Correct | 32 ms | 41464 KB | Output is correct |
4 | Correct | 31 ms | 41464 KB | Output is correct |
5 | Correct | 32 ms | 41464 KB | Output is correct |
6 | Correct | 32 ms | 41464 KB | Output is correct |
7 | Correct | 32 ms | 41464 KB | Output is correct |
8 | Correct | 39 ms | 41464 KB | Output is correct |
9 | Correct | 34 ms | 41464 KB | Output is correct |
10 | Correct | 33 ms | 41464 KB | Output is correct |
11 | Correct | 32 ms | 41464 KB | Output is correct |
12 | Correct | 31 ms | 41464 KB | Output is correct |
13 | Correct | 31 ms | 41464 KB | Output is correct |
14 | Correct | 34 ms | 41464 KB | Output is correct |
15 | Correct | 31 ms | 41464 KB | Output is correct |
16 | Correct | 33 ms | 41464 KB | Output is correct |
17 | Correct | 32 ms | 41464 KB | Output is correct |
18 | Correct | 32 ms | 41464 KB | Output is correct |
19 | Correct | 32 ms | 41464 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 38 ms | 41464 KB | Output is correct |
2 | Correct | 37 ms | 41592 KB | Output is correct |
3 | Correct | 42 ms | 41592 KB | Output is correct |
4 | Correct | 103 ms | 41592 KB | Output is correct |
5 | Correct | 333 ms | 42488 KB | Output is correct |
6 | Correct | 57 ms | 42616 KB | Output is correct |
7 | Correct | 174 ms | 42488 KB | Output is correct |
8 | Correct | 31 ms | 41464 KB | Output is correct |
9 | Correct | 31 ms | 41464 KB | Output is correct |
10 | Correct | 32 ms | 41464 KB | Output is correct |
11 | Correct | 32 ms | 41464 KB | Output is correct |
12 | Correct | 32 ms | 41464 KB | Output is correct |
13 | Correct | 33 ms | 41464 KB | Output is correct |
14 | Correct | 51 ms | 41592 KB | Output is correct |
15 | Correct | 35 ms | 41592 KB | Output is correct |
16 | Correct | 38 ms | 41592 KB | Output is correct |
17 | Correct | 40 ms | 41976 KB | Output is correct |
18 | Correct | 43 ms | 41976 KB | Output is correct |
19 | Correct | 117 ms | 41976 KB | Output is correct |
20 | Correct | 315 ms | 42488 KB | Output is correct |
21 | Correct | 49 ms | 42488 KB | Output is correct |
22 | Correct | 167 ms | 42492 KB | Output is correct |
23 | Correct | 45 ms | 42488 KB | Output is correct |
24 | Correct | 70 ms | 42492 KB | Output is correct |
25 | Correct | 312 ms | 42616 KB | Output is correct |
26 | Correct | 268 ms | 41464 KB | Output is correct |
27 | Correct | 31 ms | 41464 KB | Output is correct |
28 | Correct | 51 ms | 41592 KB | Output is correct |
29 | Correct | 33 ms | 41592 KB | Output is correct |
30 | Correct | 38 ms | 41592 KB | Output is correct |
31 | Correct | 37 ms | 41976 KB | Output is correct |
32 | Correct | 45 ms | 42356 KB | Output is correct |
33 | Correct | 119 ms | 42360 KB | Output is correct |
34 | Correct | 365 ms | 43924 KB | Output is correct |
35 | Correct | 51 ms | 43716 KB | Output is correct |
36 | Correct | 191 ms | 43852 KB | Output is correct |
37 | Correct | 38 ms | 41592 KB | Output is correct |
38 | Correct | 54 ms | 41592 KB | Output is correct |
39 | Correct | 34 ms | 41464 KB | Output is correct |
40 | Correct | 32 ms | 41464 KB | Output is correct |
41 | Correct | 33 ms | 41464 KB | Output is correct |
42 | Correct | 32 ms | 41468 KB | Output is correct |