답안 #393008

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
393008 2021-04-22T14:10:07 Z patrikpavic2 K개의 묶음 (IZhO14_blocks) C++17
100 / 100
396 ms 43080 KB
#include <cstdio>
#include <stack>
#include <cstring>

#define X first
#define Y second

using namespace std;

const int N = 1e5 + 500;
const int K = 105;
const int INF = 0x3f3f3f3f;

int dp[N][K], n, k, A[N];
stack < int > S, ja, sve;

int main(){
	memset(dp, INF, sizeof(dp)); dp[0][0] = 0;
	scanf("%d%d", &n, &k);
	for(int i = 1;i <= n;i++)
		scanf("%d", A + i);
	for(int j = 1;j <= k;j++){
		S.push(0); ja.push(dp[0][j - 1]); sve.push(dp[0][j - 1]);
		for(int i = 1;i <= n;i++){
			int bst = dp[i - 1][j - 1];
			while(!S.empty() && S.top() <= A[i]){
				bst = min(bst, ja.top()); 
				S.pop(); ja.pop(); sve.pop();
			}
			S.push(A[i]);
			ja.push(bst);
			sve.push(min(sve.empty() ? INF : sve.top(), ja.top() + S.top()));
			dp[i][j] = sve.top();
		}
		for(;!S.empty();S.pop(), ja.pop(), sve.pop()); 
	}
	printf("%d\n", dp[n][k]);
	return 0;
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |  scanf("%d%d", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~
blocks.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |   scanf("%d", A + i);
      |   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 41548 KB Output is correct
2 Correct 21 ms 41572 KB Output is correct
3 Correct 24 ms 41600 KB Output is correct
4 Correct 21 ms 41468 KB Output is correct
5 Correct 21 ms 41572 KB Output is correct
6 Correct 22 ms 41524 KB Output is correct
7 Correct 21 ms 41552 KB Output is correct
8 Correct 21 ms 41504 KB Output is correct
9 Correct 21 ms 41596 KB Output is correct
10 Correct 21 ms 41596 KB Output is correct
11 Correct 21 ms 41580 KB Output is correct
12 Correct 22 ms 41540 KB Output is correct
13 Correct 24 ms 41540 KB Output is correct
14 Correct 22 ms 41540 KB Output is correct
15 Correct 21 ms 41544 KB Output is correct
16 Correct 21 ms 41600 KB Output is correct
17 Correct 21 ms 41548 KB Output is correct
18 Correct 20 ms 41512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 41480 KB Output is correct
2 Correct 20 ms 41576 KB Output is correct
3 Correct 21 ms 41484 KB Output is correct
4 Correct 21 ms 41512 KB Output is correct
5 Correct 25 ms 41604 KB Output is correct
6 Correct 25 ms 41496 KB Output is correct
7 Correct 22 ms 41600 KB Output is correct
8 Correct 22 ms 41592 KB Output is correct
9 Correct 21 ms 41556 KB Output is correct
10 Correct 21 ms 41500 KB Output is correct
11 Correct 24 ms 41540 KB Output is correct
12 Correct 21 ms 41548 KB Output is correct
13 Correct 22 ms 41464 KB Output is correct
14 Correct 21 ms 41548 KB Output is correct
15 Correct 21 ms 41548 KB Output is correct
16 Correct 21 ms 41548 KB Output is correct
17 Correct 21 ms 41508 KB Output is correct
18 Correct 21 ms 41548 KB Output is correct
19 Correct 21 ms 41548 KB Output is correct
20 Correct 21 ms 41548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 41548 KB Output is correct
2 Correct 21 ms 41572 KB Output is correct
3 Correct 24 ms 41600 KB Output is correct
4 Correct 21 ms 41468 KB Output is correct
5 Correct 21 ms 41572 KB Output is correct
6 Correct 22 ms 41524 KB Output is correct
7 Correct 21 ms 41552 KB Output is correct
8 Correct 21 ms 41504 KB Output is correct
9 Correct 21 ms 41596 KB Output is correct
10 Correct 21 ms 41596 KB Output is correct
11 Correct 21 ms 41580 KB Output is correct
12 Correct 22 ms 41540 KB Output is correct
13 Correct 24 ms 41540 KB Output is correct
14 Correct 22 ms 41540 KB Output is correct
15 Correct 21 ms 41544 KB Output is correct
16 Correct 21 ms 41600 KB Output is correct
17 Correct 21 ms 41548 KB Output is correct
18 Correct 20 ms 41512 KB Output is correct
19 Correct 21 ms 41480 KB Output is correct
20 Correct 20 ms 41576 KB Output is correct
21 Correct 21 ms 41484 KB Output is correct
22 Correct 21 ms 41512 KB Output is correct
23 Correct 25 ms 41604 KB Output is correct
24 Correct 25 ms 41496 KB Output is correct
25 Correct 22 ms 41600 KB Output is correct
26 Correct 22 ms 41592 KB Output is correct
27 Correct 21 ms 41556 KB Output is correct
28 Correct 21 ms 41500 KB Output is correct
29 Correct 24 ms 41540 KB Output is correct
30 Correct 21 ms 41548 KB Output is correct
31 Correct 22 ms 41464 KB Output is correct
32 Correct 21 ms 41548 KB Output is correct
33 Correct 21 ms 41548 KB Output is correct
34 Correct 21 ms 41548 KB Output is correct
35 Correct 21 ms 41508 KB Output is correct
36 Correct 21 ms 41548 KB Output is correct
37 Correct 21 ms 41548 KB Output is correct
38 Correct 21 ms 41548 KB Output is correct
39 Correct 21 ms 41576 KB Output is correct
40 Correct 21 ms 41548 KB Output is correct
41 Correct 21 ms 41512 KB Output is correct
42 Correct 21 ms 41596 KB Output is correct
43 Correct 21 ms 41556 KB Output is correct
44 Correct 22 ms 41592 KB Output is correct
45 Correct 21 ms 41556 KB Output is correct
46 Correct 21 ms 41580 KB Output is correct
47 Correct 21 ms 41548 KB Output is correct
48 Correct 21 ms 41472 KB Output is correct
49 Correct 21 ms 41588 KB Output is correct
50 Correct 21 ms 41548 KB Output is correct
51 Correct 20 ms 41520 KB Output is correct
52 Correct 21 ms 41524 KB Output is correct
53 Correct 21 ms 41548 KB Output is correct
54 Correct 21 ms 41576 KB Output is correct
55 Correct 21 ms 41548 KB Output is correct
56 Correct 24 ms 41536 KB Output is correct
57 Correct 21 ms 41504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 41548 KB Output is correct
2 Correct 21 ms 41572 KB Output is correct
3 Correct 24 ms 41600 KB Output is correct
4 Correct 21 ms 41468 KB Output is correct
5 Correct 21 ms 41572 KB Output is correct
6 Correct 22 ms 41524 KB Output is correct
7 Correct 21 ms 41552 KB Output is correct
8 Correct 21 ms 41504 KB Output is correct
9 Correct 21 ms 41596 KB Output is correct
10 Correct 21 ms 41596 KB Output is correct
11 Correct 21 ms 41580 KB Output is correct
12 Correct 22 ms 41540 KB Output is correct
13 Correct 24 ms 41540 KB Output is correct
14 Correct 22 ms 41540 KB Output is correct
15 Correct 21 ms 41544 KB Output is correct
16 Correct 21 ms 41600 KB Output is correct
17 Correct 21 ms 41548 KB Output is correct
18 Correct 20 ms 41512 KB Output is correct
19 Correct 21 ms 41480 KB Output is correct
20 Correct 20 ms 41576 KB Output is correct
21 Correct 21 ms 41484 KB Output is correct
22 Correct 21 ms 41512 KB Output is correct
23 Correct 25 ms 41604 KB Output is correct
24 Correct 25 ms 41496 KB Output is correct
25 Correct 22 ms 41600 KB Output is correct
26 Correct 22 ms 41592 KB Output is correct
27 Correct 21 ms 41556 KB Output is correct
28 Correct 21 ms 41500 KB Output is correct
29 Correct 24 ms 41540 KB Output is correct
30 Correct 21 ms 41548 KB Output is correct
31 Correct 22 ms 41464 KB Output is correct
32 Correct 21 ms 41548 KB Output is correct
33 Correct 21 ms 41548 KB Output is correct
34 Correct 21 ms 41548 KB Output is correct
35 Correct 21 ms 41508 KB Output is correct
36 Correct 21 ms 41548 KB Output is correct
37 Correct 21 ms 41548 KB Output is correct
38 Correct 21 ms 41548 KB Output is correct
39 Correct 21 ms 41576 KB Output is correct
40 Correct 21 ms 41548 KB Output is correct
41 Correct 21 ms 41512 KB Output is correct
42 Correct 21 ms 41596 KB Output is correct
43 Correct 21 ms 41556 KB Output is correct
44 Correct 22 ms 41592 KB Output is correct
45 Correct 21 ms 41556 KB Output is correct
46 Correct 21 ms 41580 KB Output is correct
47 Correct 21 ms 41548 KB Output is correct
48 Correct 21 ms 41472 KB Output is correct
49 Correct 21 ms 41588 KB Output is correct
50 Correct 21 ms 41548 KB Output is correct
51 Correct 20 ms 41520 KB Output is correct
52 Correct 21 ms 41524 KB Output is correct
53 Correct 21 ms 41548 KB Output is correct
54 Correct 21 ms 41576 KB Output is correct
55 Correct 21 ms 41548 KB Output is correct
56 Correct 24 ms 41536 KB Output is correct
57 Correct 21 ms 41504 KB Output is correct
58 Correct 28 ms 41676 KB Output is correct
59 Correct 29 ms 41972 KB Output is correct
60 Correct 38 ms 41968 KB Output is correct
61 Correct 102 ms 42052 KB Output is correct
62 Correct 320 ms 42572 KB Output is correct
63 Correct 46 ms 42548 KB Output is correct
64 Correct 178 ms 42568 KB Output is correct
65 Correct 21 ms 41572 KB Output is correct
66 Correct 22 ms 41596 KB Output is correct
67 Correct 21 ms 41548 KB Output is correct
68 Correct 22 ms 41580 KB Output is correct
69 Correct 21 ms 41548 KB Output is correct
70 Correct 23 ms 41548 KB Output is correct
71 Correct 45 ms 41628 KB Output is correct
72 Correct 23 ms 41584 KB Output is correct
73 Correct 28 ms 41632 KB Output is correct
74 Correct 29 ms 42060 KB Output is correct
75 Correct 35 ms 42056 KB Output is correct
76 Correct 106 ms 41968 KB Output is correct
77 Correct 367 ms 42648 KB Output is correct
78 Correct 44 ms 42608 KB Output is correct
79 Correct 189 ms 42640 KB Output is correct
80 Correct 41 ms 42588 KB Output is correct
81 Correct 77 ms 42572 KB Output is correct
82 Correct 396 ms 42648 KB Output is correct
83 Correct 25 ms 41544 KB Output is correct
84 Correct 22 ms 41488 KB Output is correct
85 Correct 43 ms 41676 KB Output is correct
86 Correct 22 ms 41704 KB Output is correct
87 Correct 29 ms 41700 KB Output is correct
88 Correct 29 ms 42200 KB Output is correct
89 Correct 35 ms 42164 KB Output is correct
90 Correct 105 ms 42276 KB Output is correct
91 Correct 374 ms 43080 KB Output is correct
92 Correct 52 ms 43040 KB Output is correct
93 Correct 184 ms 43040 KB Output is correct
94 Correct 23 ms 41700 KB Output is correct
95 Correct 40 ms 41608 KB Output is correct
96 Correct 21 ms 41604 KB Output is correct
97 Correct 22 ms 41596 KB Output is correct
98 Correct 22 ms 41552 KB Output is correct
99 Correct 23 ms 41548 KB Output is correct