Submission #340181

# Submission time Handle Problem Language Result Execution time Memory
340181 2020-12-27T09:02:30 Z _ani K blocks (IZhO14_blocks) C++17
0 / 100
1 ms 364 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;
	if (k != 1)
		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 = ((curk == 1) ? i : 1); sz <= i - curk + 1; sz++)
			{
				/*if (i == 5)
				{
					BUGO(curk);
					BUGO(sz);
					BUGO(Mx(1, 1, n, i - sz + 1, i));
				}*/
				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;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -