답안 #218740

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
218740 2020-04-02T15:47:06 Z someone_aa K개의 묶음 (IZhO14_blocks) C++17
100 / 100
397 ms 88700 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 100100;
const int maxk = 110;
ll n, k;
ll dp[maxn][maxk];
ll arr[maxn];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cin>>n>>k;
	ll prefmax = 0LL;

	for(int i=0;i<=n;i++) {
		for(int j=0;j<=k;j++) {
			dp[i][j] = (INT_MAX);
		}
	}

	for(int i=1;i<=n;i++) {
		cin>>arr[i];
		prefmax = max(prefmax, arr[i]);
		dp[i][1] = prefmax;
	}


	for(int d=2;d<=k;d++) {
		stack<ll>dps, arrs;
		for(int i=1;i<=n;i++) {
			ll curr = dp[i-1][d-1];

			while(!arrs.empty() && arrs.top() < arr[i]) {
				curr = min(curr, dps.top());
				arrs.pop();
				dps.pop();
			}

			if(arrs.empty() || arrs.top() + dps.top() >= curr + arr[i]) {
				arrs.push(arr[i]);
				dps.push(curr);
			}

			if(i >= d) dp[i][d] = arrs.top() + dps.top();
		}
	}
	cout<<dp[n][k]<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 7 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 9088 KB Output is correct
2 Correct 35 ms 39296 KB Output is correct
3 Correct 31 ms 39296 KB Output is correct
4 Correct 90 ms 39288 KB Output is correct
5 Correct 291 ms 87928 KB Output is correct
6 Correct 64 ms 87928 KB Output is correct
7 Correct 155 ms 87928 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 1280 KB Output is correct
13 Correct 5 ms 1280 KB Output is correct
14 Correct 23 ms 9088 KB Output is correct
15 Correct 10 ms 9088 KB Output is correct
16 Correct 17 ms 9088 KB Output is correct
17 Correct 33 ms 39304 KB Output is correct
18 Correct 33 ms 39296 KB Output is correct
19 Correct 108 ms 39288 KB Output is correct
20 Correct 317 ms 87928 KB Output is correct
21 Correct 71 ms 87928 KB Output is correct
22 Correct 167 ms 87928 KB Output is correct
23 Correct 57 ms 87928 KB Output is correct
24 Correct 80 ms 87928 KB Output is correct
25 Correct 330 ms 88056 KB Output is correct
26 Correct 5 ms 1280 KB Output is correct
27 Correct 5 ms 1280 KB Output is correct
28 Correct 27 ms 9216 KB Output is correct
29 Correct 10 ms 9216 KB Output is correct
30 Correct 15 ms 9216 KB Output is correct
31 Correct 26 ms 39296 KB Output is correct
32 Correct 33 ms 39608 KB Output is correct
33 Correct 116 ms 39644 KB Output is correct
34 Correct 397 ms 88696 KB Output is correct
35 Correct 63 ms 88696 KB Output is correct
36 Correct 204 ms 88700 KB Output is correct
37 Correct 10 ms 9088 KB Output is correct
38 Correct 20 ms 9088 KB Output is correct
39 Correct 5 ms 1280 KB Output is correct
40 Correct 5 ms 1152 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 5 ms 384 KB Output is correct