답안 #340179

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
340179 2020-12-27T08:46:51 Z _ani K개의 묶음 (IZhO14_blocks) C++17
0 / 100
1 ms 492 KB
#define BUGO(x) cerr << #x << " = " << (x) << '\n';
#include <iostream>
#include <algorithm>
using namespace std;
int dp[100'002][102], a[100'002], pref[100'002];
int mx[4 * 100'002];
void Build(int v, int vl, int vr)
{
	if (vl == vr)
	{
		mx[v] = a[vl];
		return;
	}
	int m = (vl + vr) / 2;
	Build(v * 2, vl, m);
	Build(v * 2 + 1, m + 1, vr);
	mx[v] = max(mx[v * 2], mx[v * 2 + 1]);
}
int Mx(int v, int vl, int vr, int l, int r)
{
	if (vl == vr)
		return mx[v];
	int res = 0;
	int m = (vl + vr) / 2;
	if (l <= m)
		res = max(res, Mx(v * 2, vl, m, l, min(r, m)));
	if (r > m)res = max(res, Mx(v * 2 + 1, m + 1, vr, max(l, m + 1), r));
	return res;
}
int main()
{
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	Build(1, 1, n);
	for (int i = 1; i <= n; i++)
		for (int curk = 1; curk <= k; curk++)
			dp[i][curk] = 1'000'000'000;
	dp[1][1] = a[1];
	for (int i = 2; i <= n; i++)
		for (int curk = max(1, k - n + i); curk <= min(i, k - ((n - i) ? 1 : 0)); curk++)
			for (int sz = 1; sz < i - curk + 1; sz++)
			{
			/*	if (i == 3)
				{
					BUGO(curk);
					BUGO(sz);
				}*/
				dp[i][curk] = min(dp[i][curk], dp[i - sz][curk - 1] + Mx(1, 1, n, i - sz + 1, i));
			}
	/*for (int i = 1; i <= n; i++)
	{
		for (int curk = 0; curk <= k; curk++)
			cerr << dp[i][curk] << ' ';
		cerr << '\n';
	}*/
	cout << dp[n][k] << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -