Submission #430982

# Submission time Handle Problem Language Result Execution time Memory
430982 2021-06-17T08:41:49 Z haxorman K blocks (IZhO14_blocks) C++14
53 / 100
10 ms 10188 KB
#include <bits/stdc++.h>
using namespace std;

const int mxN = 107;
const int mxV = 1e6 + 7;
const int INF = 1e9 + 7;

int n, arr[mxN], dp[mxN][mxN][mxN], conv[mxV], unconv[mxN];

int rec(int i, int k, int prev_max) {
	if (i > n) {
		return (!k ? 0 : INF);
	}

	if (i <= n && !k) {
		return INF;
	}

	prev_max = max(prev_max, arr[i]);
	if (dp[i][k][prev_max] != -1) {
		return dp[i][k][prev_max];
	}


	int choose = rec(i + 1, k - 1, 0) + unconv[prev_max];
	int skip = rec(i + 1, k, prev_max);

	dp[i][k][prev_max] = min(choose, skip);
	return min(choose, skip); 
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    memset(dp, -1, sizeof(dp));

    int k;
    cin >> n >> k;

    vector<int> vec;
	for (int i = 1; i <= n; ++i) {
		cin >> arr[i];
		vec.push_back(arr[i]);
	}
	sort(vec.begin(), vec.end());

	int ind = 1;
	for (int i = 0; i < n; ++i) {
		if (!conv[vec[i]]) {
			conv[vec[i]] = ind++;
		}
	}
	assert(ind < 107);

	for (int i = 1; i <= n; ++i) {
		unconv[conv[arr[i]]] = arr[i];
		arr[i] = conv[arr[i]];
	}

	cout << rec(1, k, 0) << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5068 KB Output is correct
2 Correct 4 ms 5068 KB Output is correct
3 Correct 3 ms 5068 KB Output is correct
4 Correct 4 ms 5068 KB Output is correct
5 Correct 3 ms 5068 KB Output is correct
6 Correct 3 ms 5068 KB Output is correct
7 Correct 3 ms 5068 KB Output is correct
8 Correct 3 ms 5080 KB Output is correct
9 Correct 3 ms 5068 KB Output is correct
10 Correct 4 ms 5068 KB Output is correct
11 Correct 3 ms 5068 KB Output is correct
12 Correct 3 ms 5068 KB Output is correct
13 Correct 3 ms 5452 KB Output is correct
14 Correct 4 ms 5068 KB Output is correct
15 Correct 4 ms 5452 KB Output is correct
16 Correct 3 ms 5068 KB Output is correct
17 Correct 3 ms 5068 KB Output is correct
18 Correct 3 ms 5068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5068 KB Output is correct
2 Correct 4 ms 5068 KB Output is correct
3 Correct 3 ms 5068 KB Output is correct
4 Correct 3 ms 5068 KB Output is correct
5 Correct 3 ms 5068 KB Output is correct
6 Correct 3 ms 5068 KB Output is correct
7 Correct 3 ms 5068 KB Output is correct
8 Correct 2 ms 5068 KB Output is correct
9 Correct 3 ms 5068 KB Output is correct
10 Correct 3 ms 5068 KB Output is correct
11 Correct 3 ms 5068 KB Output is correct
12 Correct 3 ms 5068 KB Output is correct
13 Correct 3 ms 5068 KB Output is correct
14 Correct 3 ms 5068 KB Output is correct
15 Correct 3 ms 5068 KB Output is correct
16 Correct 3 ms 5068 KB Output is correct
17 Correct 3 ms 5048 KB Output is correct
18 Correct 4 ms 5068 KB Output is correct
19 Correct 3 ms 5068 KB Output is correct
20 Correct 3 ms 5068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5068 KB Output is correct
2 Correct 4 ms 5068 KB Output is correct
3 Correct 3 ms 5068 KB Output is correct
4 Correct 4 ms 5068 KB Output is correct
5 Correct 3 ms 5068 KB Output is correct
6 Correct 3 ms 5068 KB Output is correct
7 Correct 3 ms 5068 KB Output is correct
8 Correct 3 ms 5080 KB Output is correct
9 Correct 3 ms 5068 KB Output is correct
10 Correct 4 ms 5068 KB Output is correct
11 Correct 3 ms 5068 KB Output is correct
12 Correct 3 ms 5068 KB Output is correct
13 Correct 3 ms 5452 KB Output is correct
14 Correct 4 ms 5068 KB Output is correct
15 Correct 4 ms 5452 KB Output is correct
16 Correct 3 ms 5068 KB Output is correct
17 Correct 3 ms 5068 KB Output is correct
18 Correct 3 ms 5068 KB Output is correct
19 Correct 3 ms 5068 KB Output is correct
20 Correct 4 ms 5068 KB Output is correct
21 Correct 3 ms 5068 KB Output is correct
22 Correct 3 ms 5068 KB Output is correct
23 Correct 3 ms 5068 KB Output is correct
24 Correct 3 ms 5068 KB Output is correct
25 Correct 3 ms 5068 KB Output is correct
26 Correct 2 ms 5068 KB Output is correct
27 Correct 3 ms 5068 KB Output is correct
28 Correct 3 ms 5068 KB Output is correct
29 Correct 3 ms 5068 KB Output is correct
30 Correct 3 ms 5068 KB Output is correct
31 Correct 3 ms 5068 KB Output is correct
32 Correct 3 ms 5068 KB Output is correct
33 Correct 3 ms 5068 KB Output is correct
34 Correct 3 ms 5068 KB Output is correct
35 Correct 3 ms 5048 KB Output is correct
36 Correct 4 ms 5068 KB Output is correct
37 Correct 3 ms 5068 KB Output is correct
38 Correct 3 ms 5068 KB Output is correct
39 Correct 4 ms 5068 KB Output is correct
40 Correct 3 ms 5068 KB Output is correct
41 Correct 3 ms 5068 KB Output is correct
42 Correct 3 ms 5068 KB Output is correct
43 Correct 3 ms 5068 KB Output is correct
44 Correct 4 ms 5068 KB Output is correct
45 Correct 3 ms 5068 KB Output is correct
46 Correct 3 ms 5068 KB Output is correct
47 Correct 3 ms 5068 KB Output is correct
48 Correct 3 ms 5068 KB Output is correct
49 Correct 3 ms 5068 KB Output is correct
50 Correct 4 ms 5068 KB Output is correct
51 Correct 3 ms 5068 KB Output is correct
52 Correct 4 ms 5488 KB Output is correct
53 Correct 4 ms 5068 KB Output is correct
54 Correct 4 ms 5452 KB Output is correct
55 Correct 4 ms 5148 KB Output is correct
56 Correct 3 ms 5068 KB Output is correct
57 Correct 5 ms 5068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5068 KB Output is correct
2 Correct 4 ms 5068 KB Output is correct
3 Correct 3 ms 5068 KB Output is correct
4 Correct 4 ms 5068 KB Output is correct
5 Correct 3 ms 5068 KB Output is correct
6 Correct 3 ms 5068 KB Output is correct
7 Correct 3 ms 5068 KB Output is correct
8 Correct 3 ms 5080 KB Output is correct
9 Correct 3 ms 5068 KB Output is correct
10 Correct 4 ms 5068 KB Output is correct
11 Correct 3 ms 5068 KB Output is correct
12 Correct 3 ms 5068 KB Output is correct
13 Correct 3 ms 5452 KB Output is correct
14 Correct 4 ms 5068 KB Output is correct
15 Correct 4 ms 5452 KB Output is correct
16 Correct 3 ms 5068 KB Output is correct
17 Correct 3 ms 5068 KB Output is correct
18 Correct 3 ms 5068 KB Output is correct
19 Correct 3 ms 5068 KB Output is correct
20 Correct 4 ms 5068 KB Output is correct
21 Correct 3 ms 5068 KB Output is correct
22 Correct 3 ms 5068 KB Output is correct
23 Correct 3 ms 5068 KB Output is correct
24 Correct 3 ms 5068 KB Output is correct
25 Correct 3 ms 5068 KB Output is correct
26 Correct 2 ms 5068 KB Output is correct
27 Correct 3 ms 5068 KB Output is correct
28 Correct 3 ms 5068 KB Output is correct
29 Correct 3 ms 5068 KB Output is correct
30 Correct 3 ms 5068 KB Output is correct
31 Correct 3 ms 5068 KB Output is correct
32 Correct 3 ms 5068 KB Output is correct
33 Correct 3 ms 5068 KB Output is correct
34 Correct 3 ms 5068 KB Output is correct
35 Correct 3 ms 5048 KB Output is correct
36 Correct 4 ms 5068 KB Output is correct
37 Correct 3 ms 5068 KB Output is correct
38 Correct 3 ms 5068 KB Output is correct
39 Correct 4 ms 5068 KB Output is correct
40 Correct 3 ms 5068 KB Output is correct
41 Correct 3 ms 5068 KB Output is correct
42 Correct 3 ms 5068 KB Output is correct
43 Correct 3 ms 5068 KB Output is correct
44 Correct 4 ms 5068 KB Output is correct
45 Correct 3 ms 5068 KB Output is correct
46 Correct 3 ms 5068 KB Output is correct
47 Correct 3 ms 5068 KB Output is correct
48 Correct 3 ms 5068 KB Output is correct
49 Correct 3 ms 5068 KB Output is correct
50 Correct 4 ms 5068 KB Output is correct
51 Correct 3 ms 5068 KB Output is correct
52 Correct 4 ms 5488 KB Output is correct
53 Correct 4 ms 5068 KB Output is correct
54 Correct 4 ms 5452 KB Output is correct
55 Correct 4 ms 5148 KB Output is correct
56 Correct 3 ms 5068 KB Output is correct
57 Correct 5 ms 5068 KB Output is correct
58 Runtime error 10 ms 10188 KB Execution killed with signal 11
59 Halted 0 ms 0 KB -