답안 #1083675

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1083675 2024-09-03T19:52:39 Z xnqs K개의 묶음 (IZhO14_blocks) C++17
0 / 100
7 ms 41644 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];

void divide(int l, int r, int optl, int optr, int idx) {
	//std::cerr << " " << l << " " << r << " " << optl << " " << optr << " " << idx << "\n";
	if (l>r) {
		return;
	}

	int m = (l+r)>>1;
	int max = 0;
	int opt = -1;
	for (int i = std::min(m, optr); i >= optl; i--) {
		max = std::max(max, arr[i]);
		if (dp[idx][m] > dp[idx-1][i-1]+max) {
			dp[idx][m] = dp[idx-1][i-1]+max;
			opt = i;
		}
	}

	divide(l,m-1,optl,opt,idx);
	divide(m+1,r,opt,optr,idx);
}

int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);

	std::cin >> x >> k;
	for (int i = 1; i <= x; i++) {
		std::cin >> arr[i];
	}

	memset(dp,0x3f,sizeof(dp));
	dp[1][0] = 0;
	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 = 2; i <= k; i++) {
		divide(1,x,1,x,i);
	}

	std::cout << dp[k][x] << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 41564 KB Output is correct
2 Correct 6 ms 41604 KB Output is correct
3 Correct 6 ms 41608 KB Output is correct
4 Correct 7 ms 41564 KB Output is correct
5 Correct 6 ms 41640 KB Output is correct
6 Correct 7 ms 41560 KB Output is correct
7 Correct 7 ms 41564 KB Output is correct
8 Correct 6 ms 41564 KB Output is correct
9 Correct 7 ms 41560 KB Output is correct
10 Correct 7 ms 41564 KB Output is correct
11 Incorrect 7 ms 41644 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 41564 KB Output is correct
2 Correct 7 ms 41624 KB Output is correct
3 Correct 7 ms 41564 KB Output is correct
4 Correct 7 ms 41564 KB Output is correct
5 Correct 6 ms 41564 KB Output is correct
6 Correct 7 ms 41516 KB Output is correct
7 Correct 6 ms 41564 KB Output is correct
8 Correct 7 ms 41604 KB Output is correct
9 Correct 7 ms 41560 KB Output is correct
10 Correct 6 ms 41564 KB Output is correct
11 Incorrect 7 ms 41564 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 41564 KB Output is correct
2 Correct 6 ms 41604 KB Output is correct
3 Correct 6 ms 41608 KB Output is correct
4 Correct 7 ms 41564 KB Output is correct
5 Correct 6 ms 41640 KB Output is correct
6 Correct 7 ms 41560 KB Output is correct
7 Correct 7 ms 41564 KB Output is correct
8 Correct 6 ms 41564 KB Output is correct
9 Correct 7 ms 41560 KB Output is correct
10 Correct 7 ms 41564 KB Output is correct
11 Incorrect 7 ms 41644 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 41564 KB Output is correct
2 Correct 6 ms 41604 KB Output is correct
3 Correct 6 ms 41608 KB Output is correct
4 Correct 7 ms 41564 KB Output is correct
5 Correct 6 ms 41640 KB Output is correct
6 Correct 7 ms 41560 KB Output is correct
7 Correct 7 ms 41564 KB Output is correct
8 Correct 6 ms 41564 KB Output is correct
9 Correct 7 ms 41560 KB Output is correct
10 Correct 7 ms 41564 KB Output is correct
11 Incorrect 7 ms 41644 KB Output isn't correct
12 Halted 0 ms 0 KB -