Submission #646294

# Submission time Handle Problem Language Result Execution time Memory
646294 2022-09-29T12:06:52 Z ymm K blocks (IZhO14_blocks) C++17
53 / 100
1000 ms 252564 KB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

const int N = 100'032;
const int K = 110;
const ll inf = 1e15;
ll dp[K][N];
ll a[N];
int n;

ll seg[K][2*N];
ll get(int k, int l, int r)
{
	l += N; r += N;
	ll ans = inf;
	while (l < r) {
		if (l&1) ans = min(ans, seg[k][l++]);
		if (r&1) ans = min(ans, seg[k][--r]);
		l /= 2; r /= 2;
	}
	return ans;
}
void up(int k, int i, ll x)
{
	i += N;
	while (i) {
		seg[k][i] = min(seg[k][i], x);
		i /= 2;
	}
}

int main()
{
	cin.tie(0) -> sync_with_stdio(false);
	int k;
	cin >> n >> k;
	Loop (i,0,n)
		cin >> a[i];
	memset(seg, 32 /* inf */, sizeof(seg));
	dp[1][0] = a[0];
	up(1, 0, dp[1][0]);
	Loop (i,2,k+1)
		dp[i][0] = inf;
	vector<int> vec;
	vec.push_back(0);
	Loop (i,1,n) {
		while (vec.size() && a[vec.back()] < a[i])
			vec.pop_back();
		dp[1][i] = max(a[i], dp[1][i-1]);
		up(1, i, dp[1][i]);
		Loop (j,2,k+1) {
			dp[j][i] = get(j-1, vec.size()?
			                    vec.back():
			                    0, i) + a[i];
			if (vec.size()) {
				dp[j][i] = min(dp[j][i],
				               dp[j][vec.back()]);
			}
			up(j, i, dp[j][i]);
		}
		vec.push_back(i);
	}	
	cout << dp[k][n-1] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 66 ms 172504 KB Output is correct
2 Correct 65 ms 172492 KB Output is correct
3 Correct 64 ms 172516 KB Output is correct
4 Correct 64 ms 172476 KB Output is correct
5 Correct 66 ms 172560 KB Output is correct
6 Correct 71 ms 172648 KB Output is correct
7 Correct 66 ms 172472 KB Output is correct
8 Correct 65 ms 172536 KB Output is correct
9 Correct 64 ms 172512 KB Output is correct
10 Correct 64 ms 172512 KB Output is correct
11 Correct 62 ms 172584 KB Output is correct
12 Correct 63 ms 172492 KB Output is correct
13 Correct 70 ms 172616 KB Output is correct
14 Correct 73 ms 172524 KB Output is correct
15 Correct 67 ms 172464 KB Output is correct
16 Correct 66 ms 172548 KB Output is correct
17 Correct 70 ms 172556 KB Output is correct
18 Correct 69 ms 172676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 172524 KB Output is correct
2 Correct 69 ms 172492 KB Output is correct
3 Correct 83 ms 172476 KB Output is correct
4 Correct 67 ms 172580 KB Output is correct
5 Correct 70 ms 172524 KB Output is correct
6 Correct 70 ms 172472 KB Output is correct
7 Correct 89 ms 172468 KB Output is correct
8 Correct 66 ms 172552 KB Output is correct
9 Correct 65 ms 172568 KB Output is correct
10 Correct 64 ms 172544 KB Output is correct
11 Correct 64 ms 172492 KB Output is correct
12 Correct 67 ms 172516 KB Output is correct
13 Correct 65 ms 172492 KB Output is correct
14 Correct 67 ms 172604 KB Output is correct
15 Correct 71 ms 172620 KB Output is correct
16 Correct 65 ms 172588 KB Output is correct
17 Correct 65 ms 172616 KB Output is correct
18 Correct 66 ms 172632 KB Output is correct
19 Correct 66 ms 172556 KB Output is correct
20 Correct 68 ms 172588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 172504 KB Output is correct
2 Correct 65 ms 172492 KB Output is correct
3 Correct 64 ms 172516 KB Output is correct
4 Correct 64 ms 172476 KB Output is correct
5 Correct 66 ms 172560 KB Output is correct
6 Correct 71 ms 172648 KB Output is correct
7 Correct 66 ms 172472 KB Output is correct
8 Correct 65 ms 172536 KB Output is correct
9 Correct 64 ms 172512 KB Output is correct
10 Correct 64 ms 172512 KB Output is correct
11 Correct 62 ms 172584 KB Output is correct
12 Correct 63 ms 172492 KB Output is correct
13 Correct 70 ms 172616 KB Output is correct
14 Correct 73 ms 172524 KB Output is correct
15 Correct 67 ms 172464 KB Output is correct
16 Correct 66 ms 172548 KB Output is correct
17 Correct 70 ms 172556 KB Output is correct
18 Correct 69 ms 172676 KB Output is correct
19 Correct 73 ms 172524 KB Output is correct
20 Correct 69 ms 172492 KB Output is correct
21 Correct 83 ms 172476 KB Output is correct
22 Correct 67 ms 172580 KB Output is correct
23 Correct 70 ms 172524 KB Output is correct
24 Correct 70 ms 172472 KB Output is correct
25 Correct 89 ms 172468 KB Output is correct
26 Correct 66 ms 172552 KB Output is correct
27 Correct 65 ms 172568 KB Output is correct
28 Correct 64 ms 172544 KB Output is correct
29 Correct 64 ms 172492 KB Output is correct
30 Correct 67 ms 172516 KB Output is correct
31 Correct 65 ms 172492 KB Output is correct
32 Correct 67 ms 172604 KB Output is correct
33 Correct 71 ms 172620 KB Output is correct
34 Correct 65 ms 172588 KB Output is correct
35 Correct 65 ms 172616 KB Output is correct
36 Correct 66 ms 172632 KB Output is correct
37 Correct 66 ms 172556 KB Output is correct
38 Correct 68 ms 172588 KB Output is correct
39 Correct 63 ms 172804 KB Output is correct
40 Correct 67 ms 172496 KB Output is correct
41 Correct 68 ms 172488 KB Output is correct
42 Correct 72 ms 172492 KB Output is correct
43 Correct 64 ms 172544 KB Output is correct
44 Correct 66 ms 172516 KB Output is correct
45 Correct 76 ms 172624 KB Output is correct
46 Correct 66 ms 172528 KB Output is correct
47 Correct 82 ms 172528 KB Output is correct
48 Correct 80 ms 172492 KB Output is correct
49 Correct 69 ms 172620 KB Output is correct
50 Correct 65 ms 172536 KB Output is correct
51 Correct 66 ms 172636 KB Output is correct
52 Correct 72 ms 172620 KB Output is correct
53 Correct 72 ms 173196 KB Output is correct
54 Correct 64 ms 173232 KB Output is correct
55 Correct 64 ms 172900 KB Output is correct
56 Correct 65 ms 173172 KB Output is correct
57 Correct 66 ms 173132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 172504 KB Output is correct
2 Correct 65 ms 172492 KB Output is correct
3 Correct 64 ms 172516 KB Output is correct
4 Correct 64 ms 172476 KB Output is correct
5 Correct 66 ms 172560 KB Output is correct
6 Correct 71 ms 172648 KB Output is correct
7 Correct 66 ms 172472 KB Output is correct
8 Correct 65 ms 172536 KB Output is correct
9 Correct 64 ms 172512 KB Output is correct
10 Correct 64 ms 172512 KB Output is correct
11 Correct 62 ms 172584 KB Output is correct
12 Correct 63 ms 172492 KB Output is correct
13 Correct 70 ms 172616 KB Output is correct
14 Correct 73 ms 172524 KB Output is correct
15 Correct 67 ms 172464 KB Output is correct
16 Correct 66 ms 172548 KB Output is correct
17 Correct 70 ms 172556 KB Output is correct
18 Correct 69 ms 172676 KB Output is correct
19 Correct 73 ms 172524 KB Output is correct
20 Correct 69 ms 172492 KB Output is correct
21 Correct 83 ms 172476 KB Output is correct
22 Correct 67 ms 172580 KB Output is correct
23 Correct 70 ms 172524 KB Output is correct
24 Correct 70 ms 172472 KB Output is correct
25 Correct 89 ms 172468 KB Output is correct
26 Correct 66 ms 172552 KB Output is correct
27 Correct 65 ms 172568 KB Output is correct
28 Correct 64 ms 172544 KB Output is correct
29 Correct 64 ms 172492 KB Output is correct
30 Correct 67 ms 172516 KB Output is correct
31 Correct 65 ms 172492 KB Output is correct
32 Correct 67 ms 172604 KB Output is correct
33 Correct 71 ms 172620 KB Output is correct
34 Correct 65 ms 172588 KB Output is correct
35 Correct 65 ms 172616 KB Output is correct
36 Correct 66 ms 172632 KB Output is correct
37 Correct 66 ms 172556 KB Output is correct
38 Correct 68 ms 172588 KB Output is correct
39 Correct 63 ms 172804 KB Output is correct
40 Correct 67 ms 172496 KB Output is correct
41 Correct 68 ms 172488 KB Output is correct
42 Correct 72 ms 172492 KB Output is correct
43 Correct 64 ms 172544 KB Output is correct
44 Correct 66 ms 172516 KB Output is correct
45 Correct 76 ms 172624 KB Output is correct
46 Correct 66 ms 172528 KB Output is correct
47 Correct 82 ms 172528 KB Output is correct
48 Correct 80 ms 172492 KB Output is correct
49 Correct 69 ms 172620 KB Output is correct
50 Correct 65 ms 172536 KB Output is correct
51 Correct 66 ms 172636 KB Output is correct
52 Correct 72 ms 172620 KB Output is correct
53 Correct 72 ms 173196 KB Output is correct
54 Correct 64 ms 173232 KB Output is correct
55 Correct 64 ms 172900 KB Output is correct
56 Correct 65 ms 173172 KB Output is correct
57 Correct 66 ms 173132 KB Output is correct
58 Correct 79 ms 174828 KB Output is correct
59 Correct 70 ms 173548 KB Output is correct
60 Correct 86 ms 175660 KB Output is correct
61 Correct 310 ms 199940 KB Output is correct
62 Execution timed out 1033 ms 252564 KB Time limit exceeded
63 Halted 0 ms 0 KB -