# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
172658 | 2020-01-02T09:43:35 Z | Swan | K개의 묶음 (IZhO14_blocks) | C++14 | 229 ms | 42984 KB |
#include<bits/stdc++.h> #include <cstdio> #include <cstring> #include <stack> #include <algorithm> using namespace std; int dp[105][100005]; int a[100005]; int n,k; int main(){ scanf("%d %d",&n,&k); int maxv = 0; memset(dp,0x3f,sizeof(dp)); for (int i=1; i<=n; i++) { scanf("%d",&a[i]); maxv = max(maxv,a[i]); dp[1][i] = maxv; } for (int i=2; i<=k; i++) { stack<int> s1,s2; for (int j=1; j<=n; j++) { //cout << j << ' ' << s1.size() << endl; int my_dp = dp[i-1][j-1]; while (!s1.empty() && s1.top() < a[j]) { my_dp = min(my_dp,s2.top()); s1.pop(); s2.pop(); } if(s1.empty() || my_dp + a[j] < s1.top() + s2.top()){ s1.push(a[j]); s2.push(my_dp); } if(j >= i) dp[i][j] = s1.top() + s2.top(); } } printf("%d",dp[k][n]); } /* 6 2 1 2 3 4 5 6 */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 36 ms | 41464 KB | Output is correct |
2 | Correct | 36 ms | 41392 KB | Output is correct |
3 | Correct | 36 ms | 41336 KB | Output is correct |
4 | Correct | 36 ms | 41464 KB | Output is correct |
5 | Correct | 36 ms | 41564 KB | Output is correct |
6 | Correct | 36 ms | 41464 KB | Output is correct |
7 | Correct | 36 ms | 41464 KB | Output is correct |
8 | Correct | 36 ms | 41540 KB | Output is correct |
9 | Correct | 42 ms | 41336 KB | Output is correct |
10 | Correct | 36 ms | 41336 KB | Output is correct |
11 | Correct | 37 ms | 41464 KB | Output is correct |
12 | Correct | 40 ms | 41592 KB | Output is correct |
13 | Correct | 42 ms | 41448 KB | Output is correct |
14 | Correct | 41 ms | 41468 KB | Output is correct |
15 | Correct | 41 ms | 41464 KB | Output is correct |
16 | Correct | 42 ms | 41464 KB | Output is correct |
17 | Correct | 41 ms | 41464 KB | Output is correct |
18 | Correct | 41 ms | 41392 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 45 ms | 41464 KB | Output is correct |
2 | Correct | 41 ms | 41336 KB | Output is correct |
3 | Correct | 41 ms | 41464 KB | Output is correct |
4 | Correct | 42 ms | 41464 KB | Output is correct |
5 | Correct | 41 ms | 41464 KB | Output is correct |
6 | Correct | 36 ms | 41336 KB | Output is correct |
7 | Correct | 36 ms | 41464 KB | Output is correct |
8 | Correct | 36 ms | 41464 KB | Output is correct |
9 | Correct | 41 ms | 41464 KB | Output is correct |
10 | Correct | 24 ms | 41464 KB | Output is correct |
11 | Correct | 36 ms | 41464 KB | Output is correct |
12 | Correct | 36 ms | 41464 KB | Output is correct |
13 | Correct | 36 ms | 41476 KB | Output is correct |
14 | Correct | 36 ms | 41464 KB | Output is correct |
15 | Correct | 36 ms | 41464 KB | Output is correct |
16 | Correct | 41 ms | 41464 KB | Output is correct |
17 | Correct | 36 ms | 41468 KB | Output is correct |
18 | Correct | 36 ms | 41464 KB | Output is correct |
19 | Correct | 36 ms | 41464 KB | Output is correct |
20 | Correct | 36 ms | 41468 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 36 ms | 41464 KB | Output is correct |
2 | Correct | 36 ms | 41464 KB | Output is correct |
3 | Correct | 36 ms | 41536 KB | Output is correct |
4 | Correct | 36 ms | 41464 KB | Output is correct |
5 | Correct | 36 ms | 41464 KB | Output is correct |
6 | Correct | 36 ms | 41464 KB | Output is correct |
7 | Correct | 36 ms | 41464 KB | Output is correct |
8 | Correct | 36 ms | 41464 KB | Output is correct |
9 | Correct | 36 ms | 41340 KB | Output is correct |
10 | Correct | 36 ms | 41464 KB | Output is correct |
11 | Correct | 36 ms | 41412 KB | Output is correct |
12 | Correct | 36 ms | 41464 KB | Output is correct |
13 | Correct | 38 ms | 41464 KB | Output is correct |
14 | Correct | 36 ms | 41400 KB | Output is correct |
15 | Correct | 36 ms | 41464 KB | Output is correct |
16 | Correct | 36 ms | 41464 KB | Output is correct |
17 | Correct | 38 ms | 41464 KB | Output is correct |
18 | Correct | 38 ms | 41548 KB | Output is correct |
19 | Correct | 37 ms | 41464 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 40 ms | 41464 KB | Output is correct |
2 | Correct | 42 ms | 41932 KB | Output is correct |
3 | Correct | 45 ms | 41880 KB | Output is correct |
4 | Correct | 76 ms | 41916 KB | Output is correct |
5 | Correct | 162 ms | 42488 KB | Output is correct |
6 | Correct | 52 ms | 42488 KB | Output is correct |
7 | Correct | 96 ms | 42488 KB | Output is correct |
8 | Correct | 37 ms | 41464 KB | Output is correct |
9 | Correct | 37 ms | 41468 KB | Output is correct |
10 | Correct | 36 ms | 41464 KB | Output is correct |
11 | Correct | 36 ms | 41468 KB | Output is correct |
12 | Correct | 36 ms | 41464 KB | Output is correct |
13 | Correct | 36 ms | 41468 KB | Output is correct |
14 | Correct | 49 ms | 41668 KB | Output is correct |
15 | Correct | 38 ms | 41592 KB | Output is correct |
16 | Correct | 40 ms | 41592 KB | Output is correct |
17 | Correct | 43 ms | 41848 KB | Output is correct |
18 | Correct | 46 ms | 41848 KB | Output is correct |
19 | Correct | 77 ms | 41820 KB | Output is correct |
20 | Correct | 144 ms | 42488 KB | Output is correct |
21 | Correct | 56 ms | 42488 KB | Output is correct |
22 | Correct | 95 ms | 42488 KB | Output is correct |
23 | Correct | 52 ms | 42488 KB | Output is correct |
24 | Correct | 60 ms | 42488 KB | Output is correct |
25 | Correct | 153 ms | 42532 KB | Output is correct |
26 | Correct | 37 ms | 41464 KB | Output is correct |
27 | Correct | 37 ms | 41464 KB | Output is correct |
28 | Correct | 54 ms | 41592 KB | Output is correct |
29 | Correct | 38 ms | 41592 KB | Output is correct |
30 | Correct | 42 ms | 41720 KB | Output is correct |
31 | Correct | 42 ms | 41848 KB | Output is correct |
32 | Correct | 47 ms | 42080 KB | Output is correct |
33 | Correct | 100 ms | 42104 KB | Output is correct |
34 | Correct | 229 ms | 42976 KB | Output is correct |
35 | Correct | 54 ms | 42744 KB | Output is correct |
36 | Correct | 127 ms | 42984 KB | Output is correct |
37 | Correct | 39 ms | 41592 KB | Output is correct |
38 | Correct | 48 ms | 41492 KB | Output is correct |
39 | Correct | 37 ms | 41464 KB | Output is correct |
40 | Correct | 36 ms | 41464 KB | Output is correct |
41 | Correct | 36 ms | 41464 KB | Output is correct |
42 | Correct | 37 ms | 41464 KB | Output is correct |