답안 #687092

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
687092 2023-01-26T06:08:57 Z GudStonks K개의 묶음 (IZhO14_blocks) C++17
100 / 100
243 ms 81468 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ft first
#define sd second
const ll MOD = 1e9+7;
ll n, k, arr[100005], dp[100005][101];
void fun(){
	memset(arr, 0x3f, sizeof(arr));
	cin>>n>>k;
	for(int i = 1; i <= n; i++)cin>>arr[i];
	for(int i = 1; i <= n; i++)dp[i][1] = max(arr[i], dp[i - 1][1]);
	for(int j = 2; j <= k; j++){
		stack<pair<ll, ll> >st;
		for(int i = j; i <= n - (k - j); i++){
			ll x = dp[i - 1][j - 1];
			while(!st.empty() && arr[st.top().ft] <= arr[i]){
				x = min(x, st.top().sd);
				st.pop();
			}
			dp[i][j] = min(x + arr[i], (!st.empty() ? dp[st.top().ft][j] : (ll)2e18));
			st.push({i, x});
		}
	}
	cout<<dp[n][k];
}

int  main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int ttt = 1;
	//cin>>ttt;
	while(ttt--)fun();
}




# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 2 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 2 ms 1112 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 1112 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
16 Correct 1 ms 1112 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1112 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1112 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 1112 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 1 ms 1120 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 1 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 2 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 2 ms 1112 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 1112 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
16 Correct 1 ms 1112 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 1 ms 1108 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 1 ms 1112 KB Output is correct
23 Correct 1 ms 1108 KB Output is correct
24 Correct 1 ms 1108 KB Output is correct
25 Correct 1 ms 980 KB Output is correct
26 Correct 1 ms 1108 KB Output is correct
27 Correct 1 ms 1112 KB Output is correct
28 Correct 1 ms 1108 KB Output is correct
29 Correct 1 ms 1108 KB Output is correct
30 Correct 1 ms 1112 KB Output is correct
31 Correct 1 ms 1108 KB Output is correct
32 Correct 1 ms 1108 KB Output is correct
33 Correct 1 ms 1120 KB Output is correct
34 Correct 1 ms 1108 KB Output is correct
35 Correct 1 ms 1108 KB Output is correct
36 Correct 1 ms 1108 KB Output is correct
37 Correct 1 ms 1108 KB Output is correct
38 Correct 1 ms 1108 KB Output is correct
39 Correct 1 ms 1108 KB Output is correct
40 Correct 1 ms 1108 KB Output is correct
41 Correct 1 ms 1108 KB Output is correct
42 Correct 2 ms 1108 KB Output is correct
43 Correct 1 ms 1108 KB Output is correct
44 Correct 1 ms 1112 KB Output is correct
45 Correct 1 ms 1112 KB Output is correct
46 Correct 1 ms 1108 KB Output is correct
47 Correct 1 ms 1108 KB Output is correct
48 Correct 1 ms 1108 KB Output is correct
49 Correct 1 ms 1112 KB Output is correct
50 Correct 1 ms 1108 KB Output is correct
51 Correct 1 ms 1108 KB Output is correct
52 Correct 1 ms 1116 KB Output is correct
53 Correct 1 ms 1236 KB Output is correct
54 Correct 1 ms 1108 KB Output is correct
55 Correct 1 ms 1108 KB Output is correct
56 Correct 1 ms 1108 KB Output is correct
57 Correct 1 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 2 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 2 ms 1112 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 1112 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
16 Correct 1 ms 1112 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 1 ms 1108 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 1 ms 1112 KB Output is correct
23 Correct 1 ms 1108 KB Output is correct
24 Correct 1 ms 1108 KB Output is correct
25 Correct 1 ms 980 KB Output is correct
26 Correct 1 ms 1108 KB Output is correct
27 Correct 1 ms 1112 KB Output is correct
28 Correct 1 ms 1108 KB Output is correct
29 Correct 1 ms 1108 KB Output is correct
30 Correct 1 ms 1112 KB Output is correct
31 Correct 1 ms 1108 KB Output is correct
32 Correct 1 ms 1108 KB Output is correct
33 Correct 1 ms 1120 KB Output is correct
34 Correct 1 ms 1108 KB Output is correct
35 Correct 1 ms 1108 KB Output is correct
36 Correct 1 ms 1108 KB Output is correct
37 Correct 1 ms 1108 KB Output is correct
38 Correct 1 ms 1108 KB Output is correct
39 Correct 1 ms 1108 KB Output is correct
40 Correct 1 ms 1108 KB Output is correct
41 Correct 1 ms 1108 KB Output is correct
42 Correct 2 ms 1108 KB Output is correct
43 Correct 1 ms 1108 KB Output is correct
44 Correct 1 ms 1112 KB Output is correct
45 Correct 1 ms 1112 KB Output is correct
46 Correct 1 ms 1108 KB Output is correct
47 Correct 1 ms 1108 KB Output is correct
48 Correct 1 ms 1108 KB Output is correct
49 Correct 1 ms 1112 KB Output is correct
50 Correct 1 ms 1108 KB Output is correct
51 Correct 1 ms 1108 KB Output is correct
52 Correct 1 ms 1116 KB Output is correct
53 Correct 1 ms 1236 KB Output is correct
54 Correct 1 ms 1108 KB Output is correct
55 Correct 1 ms 1108 KB Output is correct
56 Correct 1 ms 1108 KB Output is correct
57 Correct 1 ms 1108 KB Output is correct
58 Correct 7 ms 9044 KB Output is correct
59 Correct 23 ms 36524 KB Output is correct
60 Correct 22 ms 36524 KB Output is correct
61 Correct 62 ms 36548 KB Output is correct
62 Correct 229 ms 80836 KB Output is correct
63 Correct 42 ms 80832 KB Output is correct
64 Correct 114 ms 80856 KB Output is correct
65 Correct 1 ms 1108 KB Output is correct
66 Correct 1 ms 1108 KB Output is correct
67 Correct 1 ms 1108 KB Output is correct
68 Correct 1 ms 1108 KB Output is correct
69 Correct 1 ms 1884 KB Output is correct
70 Correct 1 ms 1876 KB Output is correct
71 Correct 19 ms 9088 KB Output is correct
72 Correct 5 ms 9044 KB Output is correct
73 Correct 8 ms 9064 KB Output is correct
74 Correct 18 ms 36444 KB Output is correct
75 Correct 23 ms 36460 KB Output is correct
76 Correct 67 ms 36428 KB Output is correct
77 Correct 239 ms 80824 KB Output is correct
78 Correct 48 ms 80756 KB Output is correct
79 Correct 121 ms 80756 KB Output is correct
80 Correct 38 ms 80716 KB Output is correct
81 Correct 60 ms 80832 KB Output is correct
82 Correct 219 ms 80832 KB Output is correct
83 Correct 1 ms 1876 KB Output is correct
84 Correct 1 ms 1888 KB Output is correct
85 Correct 17 ms 9044 KB Output is correct
86 Correct 4 ms 9044 KB Output is correct
87 Correct 9 ms 9044 KB Output is correct
88 Correct 19 ms 36424 KB Output is correct
89 Correct 24 ms 36772 KB Output is correct
90 Correct 73 ms 36808 KB Output is correct
91 Correct 243 ms 81468 KB Output is correct
92 Correct 43 ms 81348 KB Output is correct
93 Correct 128 ms 81420 KB Output is correct
94 Correct 5 ms 9044 KB Output is correct
95 Correct 15 ms 9044 KB Output is correct
96 Correct 1 ms 1884 KB Output is correct
97 Correct 1 ms 1876 KB Output is correct
98 Correct 1 ms 1108 KB Output is correct
99 Correct 1 ms 1280 KB Output is correct