답안 #639617

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
639617 2022-09-10T17:58:00 Z luanaamorim K개의 묶음 (IZhO14_blocks) C++14
53 / 100
16 ms 32152 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)1e9

using namespace std;

ll n, m, arr[MAX], dp[MAX][101], maior[MAX][MAX], memo[MAX][MAX], l, r, resp;

ll f(int i, int k)
{
	if (k < 0) return INF;
	if (i > n) return (k?INF:0);
	if (~memo[i][k]) return memo[i][k];
	ll resp = INF;
	for (int j = i; j <= n; j++)
		resp = min(resp, f(j+1, k-1) + maior[i][j]);

	return memo[i][k] = resp;
}

// ll dct(int i, int j, int l, int r)
// {
// 	int mid = (i+j)>>1;
// 	//calcular dp para um k, no range [i..j]
// 	for ()




// 	int optmid = f(1, n).second;
// 	if (i == j) return f(1, n).first;
// 	return min(dct(i, mid-1, l, optmid), dct(mid+1, j, optmid, r));
// }

int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
	{
		cin >> arr[i];
		resp = max(resp, 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;
 
	dp[n+1][0] = 0;
 
	for (int i = n; i >= 1; i--)
	{
		for (int k = 1; k <= m; k++)
		{
			for (int j = i; j <= n; j++)
				dp[i][k] = min(dp[i][k], dp[j+1][k-1] + maior[i][j]);
		}
	}

	// for (int i = 1; i < m; i++)
	// 	dct(1, n, 1, n);
	memset(memo, -1, sizeof memo);
	cout << dp[1][m] << endl;


}	






# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 31572 KB Output is correct
2 Correct 12 ms 31640 KB Output is correct
3 Correct 14 ms 31576 KB Output is correct
4 Correct 13 ms 31572 KB Output is correct
5 Correct 13 ms 31584 KB Output is correct
6 Correct 16 ms 31572 KB Output is correct
7 Correct 12 ms 31644 KB Output is correct
8 Correct 15 ms 31648 KB Output is correct
9 Correct 14 ms 31632 KB Output is correct
10 Correct 13 ms 31572 KB Output is correct
11 Correct 13 ms 31668 KB Output is correct
12 Correct 14 ms 32120 KB Output is correct
13 Correct 15 ms 32060 KB Output is correct
14 Correct 13 ms 32084 KB Output is correct
15 Correct 15 ms 32096 KB Output is correct
16 Correct 14 ms 32084 KB Output is correct
17 Correct 13 ms 32152 KB Output is correct
18 Correct 13 ms 32088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 31564 KB Output is correct
2 Correct 13 ms 31540 KB Output is correct
3 Correct 16 ms 31572 KB Output is correct
4 Correct 14 ms 31624 KB Output is correct
5 Correct 13 ms 31624 KB Output is correct
6 Correct 12 ms 31592 KB Output is correct
7 Correct 13 ms 31572 KB Output is correct
8 Correct 13 ms 31572 KB Output is correct
9 Correct 14 ms 31572 KB Output is correct
10 Correct 13 ms 31656 KB Output is correct
11 Correct 15 ms 31724 KB Output is correct
12 Correct 13 ms 31640 KB Output is correct
13 Correct 13 ms 31612 KB Output is correct
14 Correct 14 ms 31700 KB Output is correct
15 Correct 13 ms 31648 KB Output is correct
16 Correct 14 ms 31700 KB Output is correct
17 Correct 13 ms 31628 KB Output is correct
18 Correct 15 ms 31672 KB Output is correct
19 Correct 14 ms 31724 KB Output is correct
20 Correct 13 ms 31700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 31572 KB Output is correct
2 Correct 12 ms 31640 KB Output is correct
3 Correct 14 ms 31576 KB Output is correct
4 Correct 13 ms 31572 KB Output is correct
5 Correct 13 ms 31584 KB Output is correct
6 Correct 16 ms 31572 KB Output is correct
7 Correct 12 ms 31644 KB Output is correct
8 Correct 15 ms 31648 KB Output is correct
9 Correct 14 ms 31632 KB Output is correct
10 Correct 13 ms 31572 KB Output is correct
11 Correct 13 ms 31668 KB Output is correct
12 Correct 14 ms 32120 KB Output is correct
13 Correct 15 ms 32060 KB Output is correct
14 Correct 13 ms 32084 KB Output is correct
15 Correct 15 ms 32096 KB Output is correct
16 Correct 14 ms 32084 KB Output is correct
17 Correct 13 ms 32152 KB Output is correct
18 Correct 13 ms 32088 KB Output is correct
19 Correct 15 ms 31564 KB Output is correct
20 Correct 13 ms 31540 KB Output is correct
21 Correct 16 ms 31572 KB Output is correct
22 Correct 14 ms 31624 KB Output is correct
23 Correct 13 ms 31624 KB Output is correct
24 Correct 12 ms 31592 KB Output is correct
25 Correct 13 ms 31572 KB Output is correct
26 Correct 13 ms 31572 KB Output is correct
27 Correct 14 ms 31572 KB Output is correct
28 Correct 13 ms 31656 KB Output is correct
29 Correct 15 ms 31724 KB Output is correct
30 Correct 13 ms 31640 KB Output is correct
31 Correct 13 ms 31612 KB Output is correct
32 Correct 14 ms 31700 KB Output is correct
33 Correct 13 ms 31648 KB Output is correct
34 Correct 14 ms 31700 KB Output is correct
35 Correct 13 ms 31628 KB Output is correct
36 Correct 15 ms 31672 KB Output is correct
37 Correct 14 ms 31724 KB Output is correct
38 Correct 13 ms 31700 KB Output is correct
39 Correct 13 ms 32084 KB Output is correct
40 Correct 13 ms 31572 KB Output is correct
41 Correct 13 ms 31572 KB Output is correct
42 Correct 14 ms 31624 KB Output is correct
43 Correct 13 ms 31572 KB Output is correct
44 Correct 13 ms 31572 KB Output is correct
45 Correct 13 ms 31532 KB Output is correct
46 Correct 13 ms 31572 KB Output is correct
47 Correct 13 ms 31656 KB Output is correct
48 Correct 13 ms 31572 KB Output is correct
49 Correct 13 ms 31560 KB Output is correct
50 Correct 14 ms 31572 KB Output is correct
51 Correct 16 ms 32100 KB Output is correct
52 Correct 14 ms 32048 KB Output is correct
53 Correct 13 ms 32064 KB Output is correct
54 Correct 14 ms 32084 KB Output is correct
55 Correct 15 ms 32108 KB Output is correct
56 Correct 13 ms 32092 KB Output is correct
57 Correct 14 ms 32084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 31572 KB Output is correct
2 Correct 12 ms 31640 KB Output is correct
3 Correct 14 ms 31576 KB Output is correct
4 Correct 13 ms 31572 KB Output is correct
5 Correct 13 ms 31584 KB Output is correct
6 Correct 16 ms 31572 KB Output is correct
7 Correct 12 ms 31644 KB Output is correct
8 Correct 15 ms 31648 KB Output is correct
9 Correct 14 ms 31632 KB Output is correct
10 Correct 13 ms 31572 KB Output is correct
11 Correct 13 ms 31668 KB Output is correct
12 Correct 14 ms 32120 KB Output is correct
13 Correct 15 ms 32060 KB Output is correct
14 Correct 13 ms 32084 KB Output is correct
15 Correct 15 ms 32096 KB Output is correct
16 Correct 14 ms 32084 KB Output is correct
17 Correct 13 ms 32152 KB Output is correct
18 Correct 13 ms 32088 KB Output is correct
19 Correct 15 ms 31564 KB Output is correct
20 Correct 13 ms 31540 KB Output is correct
21 Correct 16 ms 31572 KB Output is correct
22 Correct 14 ms 31624 KB Output is correct
23 Correct 13 ms 31624 KB Output is correct
24 Correct 12 ms 31592 KB Output is correct
25 Correct 13 ms 31572 KB Output is correct
26 Correct 13 ms 31572 KB Output is correct
27 Correct 14 ms 31572 KB Output is correct
28 Correct 13 ms 31656 KB Output is correct
29 Correct 15 ms 31724 KB Output is correct
30 Correct 13 ms 31640 KB Output is correct
31 Correct 13 ms 31612 KB Output is correct
32 Correct 14 ms 31700 KB Output is correct
33 Correct 13 ms 31648 KB Output is correct
34 Correct 14 ms 31700 KB Output is correct
35 Correct 13 ms 31628 KB Output is correct
36 Correct 15 ms 31672 KB Output is correct
37 Correct 14 ms 31724 KB Output is correct
38 Correct 13 ms 31700 KB Output is correct
39 Correct 13 ms 32084 KB Output is correct
40 Correct 13 ms 31572 KB Output is correct
41 Correct 13 ms 31572 KB Output is correct
42 Correct 14 ms 31624 KB Output is correct
43 Correct 13 ms 31572 KB Output is correct
44 Correct 13 ms 31572 KB Output is correct
45 Correct 13 ms 31532 KB Output is correct
46 Correct 13 ms 31572 KB Output is correct
47 Correct 13 ms 31656 KB Output is correct
48 Correct 13 ms 31572 KB Output is correct
49 Correct 13 ms 31560 KB Output is correct
50 Correct 14 ms 31572 KB Output is correct
51 Correct 16 ms 32100 KB Output is correct
52 Correct 14 ms 32048 KB Output is correct
53 Correct 13 ms 32064 KB Output is correct
54 Correct 14 ms 32084 KB Output is correct
55 Correct 15 ms 32108 KB Output is correct
56 Correct 13 ms 32092 KB Output is correct
57 Correct 14 ms 32084 KB Output is correct
58 Runtime error 2 ms 468 KB Execution killed with signal 11
59 Halted 0 ms 0 KB -