Submission #639630

# Submission time Handle Problem Language Result Execution time Memory
639630 2022-09-10T18:45:17 Z luanaamorim K blocks (IZhO14_blocks) C++14
0 / 100
1 ms 340 KB
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring>
#include <set>
#include <stack>
#include <bitset>
#define MAX (int) 2e3
#define ll long long
#define INF (ll) 1e15
#define dbug(x) cout << #x << ' ' << x << endl

using namespace std;

ll n, m, arr[MAX], maior[MAX][MAX], l, r, resp;
pair<ll, ll> dp[MAX][101];

void dct(int i, int j, int l, int r, int k)
{
	if (i > j) return;
	int mid = (i+j)>>1;
	dp[mid][k] = {INF, mid};
	for (int idx = max(mid, l); idx <= r; idx++)
		dp[mid][k] = min(dp[mid][k], {dp[idx+1][k-1].first + maior[mid][idx], idx});

	int optmid = dp[mid][k].second;
	dct(i, mid-1, l, optmid, k);
	dct(mid+1, j, optmid, r, k); 
}

int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		cin >> arr[i];

	for (int i = 1; i <= n; i++)
		for (int j = i; j <= n; j++)
			maior[i][j] = max(arr[j], maior[i][j-1]);
 
 	for (int i = 0; i <= n+1; i++)
		for (int j = 0; j <= m; j++)
			dp[i][j] = {INF, -1};
 
 	dp[n+1][0] = {0, 0};
	// for (int i = n; i >= 1; i--)
	// {
	// 	for (int k = 1; k <= m; k++)
	// 	{
	// 		dp[i][k] = {INF, i};
	// 		for (int j = n; j >= i; j--)
	// 			dp[i][k] = min(dp[i][k], {dp[j+1][k-1].first + maior[i][j], j});
	// 	}
	// }

	for (int i = 1; i <= m; i++)
	{
		dct(1, n, 1, n, i);
		// for (int j = 1; j <= n; j++)
		// 	cout << dp[j][i].first << ' ';
		// cout << endl;
	}

	// memset(memo, -1, sizeof memo);
	cout << dp[1][m].first  << endl;


}	






# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Incorrect 0 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Incorrect 0 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Incorrect 0 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Incorrect 0 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -