답안 #1085005

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1085005 2024-09-07T09:57:52 Z xnqs K개의 묶음 (IZhO14_blocks) C++17
53 / 100
1000 ms 19088 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <cstring>

int x, k;
int arr[100005];
int dp[105][100005];
int pge[100005];
int tree[400005];

void update(int node, int l, int r, int pos, int val) {
	if (l==r) {
		tree[node] = val;
		return;
	}

	int m = (l+r)>>1;
	if (pos<=m) {
		update(node<<1,l,m,pos,val);
	}
	else {
		update(node<<1|1,m+1,r,pos,val);
	}
	tree[node] = std::min(tree[node<<1],tree[node<<1|1]);
}

int query(int node, int l, int r, int st, int fi) {
	if (l>fi||r<st) {
		return 0x3f3f3f3f;
	}
	if (st<=l&&r<=fi) {
		return tree[node];
	}

	int m = (l+r)>>1;
	return std::min(query(node<<1,l,m,st,fi),query(node<<1|1,m+1,r,st,fi));
}

void augment(int p) {
	for (int i = 0; i < p; i++) {
		dp[p][i] = 0x3f3f3f3f;
	}
	for (int i = p; i <= x; i++) {
		dp[p][i] = 0x3f3f3f3f;
		int pos = i;
		while (pos>0) {
			int next = pge[pos];
			int tmp = query(1,0,x,next,pos-1) + arr[pos];
			dp[p][i] = std::min(dp[p][i], tmp);
			/*if (tmp-dp[p][i]>50000) {
				break;
			}*/
			pos = next;
		}
	}

	for (int i = 0; i <= x; i++) {
		update(1,0,x,i,dp[p][i]);
	}
}

int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
 
	std::cin >> x >> k;
	std::vector<int> stk;
	for (int i = 1; i <= x; i++) {
		std::cin >> arr[i];
		while (!stk.empty()&&arr[i]>=arr[stk.back()]) {
			stk.pop_back();
		}
		pge[i] = ((stk.empty()) ? 0 : stk.back());
		stk.emplace_back(i);
	}

	for (int i = 1; i <= x; i++) {
		dp[1][i] = std::max(dp[1][i-1],arr[i]);
	}
	dp[1][0] = 0x3f3f3f3f;
	for (int i = 0; i <= x; i++) {
		update(1,0,x,i,dp[1][i]);
	}
	for (int p = 2; p <= k; p++) {
		augment(p);
	}

	std::cout << dp[k][x] << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 464 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 472 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 464 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 472 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 2 ms 740 KB Output is correct
40 Correct 0 ms 464 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 464 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Correct 1 ms 472 KB Output is correct
53 Correct 2 ms 860 KB Output is correct
54 Correct 2 ms 860 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 860 KB Output is correct
57 Correct 6 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 464 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 472 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 2 ms 740 KB Output is correct
40 Correct 0 ms 464 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 464 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Correct 1 ms 472 KB Output is correct
53 Correct 2 ms 860 KB Output is correct
54 Correct 2 ms 860 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 860 KB Output is correct
57 Correct 6 ms 856 KB Output is correct
58 Correct 54 ms 1704 KB Output is correct
59 Correct 7 ms 1628 KB Output is correct
60 Correct 65 ms 2696 KB Output is correct
61 Correct 755 ms 15192 KB Output is correct
62 Execution timed out 1018 ms 19088 KB Time limit exceeded
63 Halted 0 ms 0 KB -