Submission #523628

# Submission time Handle Problem Language Result Execution time Memory
523628 2022-02-08T02:03:28 Z boykut K blocks (IZhO14_blocks) C++14
0 / 100
1 ms 204 KB
#include <bits/stdc++.h>

using namespace std;

class sparse_table {
public:
	sparse_table(vector<int>&a) : n(a.size()) {
		lg.resize(1 + n);
		lg[0] = lg[1] = 0;
		for (int i = 2; i <= n; i++)
			lg[i] = lg[i / 2] + 1;

		mx.assign(n, vector<int>(1 + lg[n]));
		for (int j = 0; j <= lg[n]; j++)
			for (int i = 0; i <= n - (1 << j); i++)
				if (j == 0) mx[i][j] = a[i];
				else mx[i][j] = max(mx[i][j-1], mx[i+(1<<(j-1))][j-1]);
	}
	int query(int l, int r) {
		int d = lg[r-l+1];
		return max(mx[l][d], mx[r-(1<<d)+1][d]);
	}
private:
	int n;
	vector<int> lg;
	vector<vector<int>> mx;
};


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n, k;
	cin >> n >> k;
	vector<int> a(1 + n);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	sparse_table st(a);
	vector<vector<int>> dp(1 + n, vector<int>(1 + k, -1));

	for (int i = 1; i <= n; i++) {
		dp[i][1] = a[i];
		if (i > 1) dp[i][1] = max(dp[i][1], dp[i-1][1]);
	}

	for (int j = 2; j <= k; j++) {
		for (int i = 1; i <= n; i++) {
			dp[i][j] = INT_MAX;
			for (int i2 = 1; i2 < i; i2++) {
				dp[i][j] = min(dp[i][j], dp[i2][j-1] + st.query(i2+1, i));
			}
		}
	}

	cout << dp[n][k] << '\n';

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