# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
38200 | 2018-01-03T02:45:09 Z | Talant | K개의 묶음 (IZhO14_blocks) | C++14 | 229 ms | 81972 KB |
#include <bits/stdc++.h> #define fr first #define sc second #define OK puts("OK"); #define pb push_back #define mk make_pair using namespace std; typedef long long ll; const ll inf = (ll)1e18 + 7; const int N = (int)1e5 + 7; int n,k; int a[N]; ll dp[101][N]; int main () { cin >> n >> k; for (int i = 1; i <= n; i ++) scanf ("%d", &a[i]); memset(dp,0x3f3f3f3f,sizeof(dp)); dp[0][0] = 0; for (int i = 1; i <= k; i ++) { stack <pair<ll,ll> > st; st.push({inf,inf}); for (int j = i; j <= n; j ++) { ll cur = dp[i - 1][j - 1]; while (!st.empty() && st.top().fr <= a[j]) { cur = min(cur,st.top().sc); st.pop(); } dp[i][j] = min(st.top().fr + st.top().sc,cur + a[j]); if (st.top().fr + st.top().sc > cur + a[j]) st.push({a[j],cur}); } } cout << dp[k][n] << endl; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 81316 KB | Output is correct |
2 | Correct | 3 ms | 81316 KB | Output is correct |
3 | Correct | 9 ms | 81316 KB | Output is correct |
4 | Correct | 0 ms | 81316 KB | Output is correct |
5 | Correct | 3 ms | 81316 KB | Output is correct |
6 | Correct | 0 ms | 81316 KB | Output is correct |
7 | Correct | 3 ms | 81316 KB | Output is correct |
8 | Correct | 0 ms | 81316 KB | Output is correct |
9 | Correct | 13 ms | 81316 KB | Output is correct |
10 | Correct | 6 ms | 81316 KB | Output is correct |
11 | Correct | 0 ms | 81316 KB | Output is correct |
12 | Correct | 3 ms | 81316 KB | Output is correct |
13 | Correct | 6 ms | 81316 KB | Output is correct |
14 | Correct | 0 ms | 81316 KB | Output is correct |
15 | Correct | 3 ms | 81316 KB | Output is correct |
16 | Correct | 16 ms | 81316 KB | Output is correct |
17 | Correct | 3 ms | 81316 KB | Output is correct |
18 | Correct | 3 ms | 81316 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 81316 KB | Output is correct |
2 | Correct | 0 ms | 81316 KB | Output is correct |
3 | Correct | 0 ms | 81316 KB | Output is correct |
4 | Correct | 16 ms | 81316 KB | Output is correct |
5 | Correct | 3 ms | 81316 KB | Output is correct |
6 | Correct | 3 ms | 81316 KB | Output is correct |
7 | Correct | 0 ms | 81316 KB | Output is correct |
8 | Correct | 3 ms | 81316 KB | Output is correct |
9 | Correct | 3 ms | 81316 KB | Output is correct |
10 | Correct | 6 ms | 81316 KB | Output is correct |
11 | Correct | 6 ms | 81316 KB | Output is correct |
12 | Correct | 3 ms | 81316 KB | Output is correct |
13 | Correct | 3 ms | 81316 KB | Output is correct |
14 | Correct | 0 ms | 81316 KB | Output is correct |
15 | Correct | 6 ms | 81316 KB | Output is correct |
16 | Correct | 0 ms | 81316 KB | Output is correct |
17 | Correct | 3 ms | 81316 KB | Output is correct |
18 | Correct | 13 ms | 81316 KB | Output is correct |
19 | Correct | 3 ms | 81316 KB | Output is correct |
20 | Correct | 9 ms | 81316 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 81316 KB | Output is correct |
2 | Correct | 13 ms | 81316 KB | Output is correct |
3 | Correct | 3 ms | 81316 KB | Output is correct |
4 | Correct | 3 ms | 81316 KB | Output is correct |
5 | Correct | 9 ms | 81316 KB | Output is correct |
6 | Correct | 6 ms | 81316 KB | Output is correct |
7 | Correct | 3 ms | 81316 KB | Output is correct |
8 | Correct | 0 ms | 81316 KB | Output is correct |
9 | Correct | 3 ms | 81316 KB | Output is correct |
10 | Correct | 6 ms | 81316 KB | Output is correct |
11 | Correct | 3 ms | 81316 KB | Output is correct |
12 | Correct | 6 ms | 81316 KB | Output is correct |
13 | Correct | 6 ms | 81316 KB | Output is correct |
14 | Correct | 16 ms | 81316 KB | Output is correct |
15 | Correct | 3 ms | 81316 KB | Output is correct |
16 | Correct | 0 ms | 81316 KB | Output is correct |
17 | Correct | 6 ms | 81316 KB | Output is correct |
18 | Correct | 3 ms | 81316 KB | Output is correct |
19 | Correct | 3 ms | 81316 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 81316 KB | Output is correct |
2 | Correct | 9 ms | 81316 KB | Output is correct |
3 | Correct | 19 ms | 81316 KB | Output is correct |
4 | Correct | 43 ms | 81316 KB | Output is correct |
5 | Correct | 143 ms | 81316 KB | Output is correct |
6 | Correct | 26 ms | 81316 KB | Output is correct |
7 | Correct | 76 ms | 81316 KB | Output is correct |
8 | Correct | 3 ms | 81316 KB | Output is correct |
9 | Correct | 6 ms | 81316 KB | Output is correct |
10 | Correct | 13 ms | 81316 KB | Output is correct |
11 | Correct | 9 ms | 81316 KB | Output is correct |
12 | Correct | 3 ms | 81316 KB | Output is correct |
13 | Correct | 3 ms | 81316 KB | Output is correct |
14 | Correct | 23 ms | 81316 KB | Output is correct |
15 | Correct | 13 ms | 81316 KB | Output is correct |
16 | Correct | 0 ms | 81316 KB | Output is correct |
17 | Correct | 16 ms | 81316 KB | Output is correct |
18 | Correct | 16 ms | 81316 KB | Output is correct |
19 | Correct | 43 ms | 81316 KB | Output is correct |
20 | Correct | 96 ms | 81316 KB | Output is correct |
21 | Correct | 36 ms | 81316 KB | Output is correct |
22 | Correct | 66 ms | 81316 KB | Output is correct |
23 | Correct | 26 ms | 81316 KB | Output is correct |
24 | Correct | 43 ms | 81316 KB | Output is correct |
25 | Correct | 109 ms | 81316 KB | Output is correct |
26 | Correct | 0 ms | 81316 KB | Output is correct |
27 | Correct | 9 ms | 81316 KB | Output is correct |
28 | Correct | 26 ms | 81448 KB | Output is correct |
29 | Correct | 13 ms | 81448 KB | Output is correct |
30 | Correct | 16 ms | 81448 KB | Output is correct |
31 | Correct | 9 ms | 81316 KB | Output is correct |
32 | Correct | 13 ms | 81576 KB | Output is correct |
33 | Correct | 79 ms | 81656 KB | Output is correct |
34 | Correct | 229 ms | 81964 KB | Output is correct |
35 | Correct | 16 ms | 81960 KB | Output is correct |
36 | Correct | 109 ms | 81972 KB | Output is correct |
37 | Correct | 6 ms | 81316 KB | Output is correct |
38 | Correct | 19 ms | 81316 KB | Output is correct |
39 | Correct | 0 ms | 81316 KB | Output is correct |
40 | Correct | 16 ms | 81316 KB | Output is correct |
41 | Correct | 13 ms | 81316 KB | Output is correct |
42 | Correct | 6 ms | 81316 KB | Output is correct |