Submission #1083712

# Submission time Handle Problem Language Result Execution time Memory
1083712 2024-09-03T20:45:40 Z xnqs K blocks (IZhO14_blocks) C++17
0 / 100
2 ms 10716 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <cstring>
#include <random>

std::mt19937 rng(53);
 
int x, k;
int arr[100005];
int dp[105][100005];
int sp_tb[17][100005];
 
int query(int l, int r) {
	int lvl = 31-__builtin_clz(r-l+1);
	return std::max(sp_tb[lvl][l], sp_tb[lvl][r-(1<<lvl)+1]);
}
 
void divide(int l, int r, int optl, int optr, int idx) {
	if (l>r) {
		return;
	}
 
	int m = (l+r)>>1;
	int opt = 0;
	for (int rep = 0; rep < 69; rep++) {
		int i = std::max(1,optl-100) + rng()%(std::min(optr+100,m)-std::max(1,optl-100)+1);
		if (dp[idx][m] > dp[idx-1][i-1]+query(i,m)) {
			dp[idx][m] = dp[idx-1][i-1]+query(i,m);
			opt = i;
		}
	}
 
	divide(l,m-1,optl,opt,idx);
	divide(m+1,r,opt,optr,idx);
}
 
int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
 
	std::cin >> x >> k;
	for (int i = 1; i <= x; i++) {
		std::cin >> arr[i];
		sp_tb[0][i] = arr[i];
	}
	for (int l = 1; l < 17; l++) {
		for (int i = 1; i+(1<<l)-1 <= x; i++) {
			sp_tb[l][i] = std::max(sp_tb[l-1][i],sp_tb[l-1][i+(1<<(l-1))]);
		}
	}
 
	dp[1][0] = 0x3f3f3f3f;
	for (int i = 1; i <= x; i++) {
		dp[1][i] = query(1,i);
	}
	for (int i = 2; i <= k; i++) {
		for (int j = 0; j <= x; j++) {
			dp[i][j] = 0x3f3f3f3f;
		}
		divide(1,x,1,x,i);
	}
 
	std::cout << dp[k][x] << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Incorrect 2 ms 8792 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6624 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 10588 KB Output is correct
17 Correct 1 ms 10716 KB Output is correct
18 Incorrect 1 ms 8540 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Incorrect 2 ms 8792 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Incorrect 2 ms 8792 KB Output isn't correct
14 Halted 0 ms 0 KB -