Submission #159700

# Submission time Handle Problem Language Result Execution time Memory
159700 2019-10-24T01:51:53 Z DrSwad K blocks (IZhO14_blocks) C++17
100 / 100
349 ms 43000 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#endif

typedef long long ll;

typedef pair<int, int> pii;
#define x first
#define y second

const int N = int(1e5) + 10;
const int K = 105;
const int INF = int(1e9);

int n, k;
int a[N];
int l[N];
int dp[K][N];
int st[N], st_len;

int main() {
	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif

	cin >> n >> k;
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);

	for (int i = 1; i <= n; i++) {
		int at = i - 1;
		while (at > 0 && a[at] < a[i]) at = l[at];
		l[i] = at;
	}

	fill(&dp[0][0], &dp[K][0], INF);
	dp[0][0] = 0;

	for (int _k = 1; _k <= k; _k++) {
		st_len = 0;
		for (int i = 0; i < _k; i++) {
			while (st_len > 0 && dp[_k - 1][st[st_len - 1]] >= dp[_k - 1][i]) st_len--;
			st[st_len++] = i;
		}
		for (int i = _k; i <= n; i++) {
			int at = lower_bound(st, st + st_len, l[i]) - st;
			dp[_k][i] = min(a[i] + dp[_k - 1][st[at]], dp[_k][l[i]]);

			while (st_len > 0 && dp[_k - 1][st[st_len - 1]] >= dp[_k - 1][i]) st_len--;
			st[st_len++] = i;
		}
	}

	cout << dp[k][n] << endl;

	return 0;
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:32:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
                               ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 39 ms 41468 KB Output is correct
2 Correct 38 ms 41464 KB Output is correct
3 Correct 38 ms 41464 KB Output is correct
4 Correct 37 ms 41464 KB Output is correct
5 Correct 38 ms 41432 KB Output is correct
6 Correct 38 ms 41464 KB Output is correct
7 Correct 38 ms 41464 KB Output is correct
8 Correct 38 ms 41492 KB Output is correct
9 Correct 38 ms 41464 KB Output is correct
10 Correct 38 ms 41464 KB Output is correct
11 Correct 38 ms 41464 KB Output is correct
12 Correct 38 ms 41464 KB Output is correct
13 Correct 38 ms 41492 KB Output is correct
14 Correct 38 ms 41464 KB Output is correct
15 Correct 39 ms 41364 KB Output is correct
16 Correct 38 ms 41464 KB Output is correct
17 Correct 38 ms 41464 KB Output is correct
18 Correct 38 ms 41464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 41492 KB Output is correct
2 Correct 37 ms 41448 KB Output is correct
3 Correct 37 ms 41464 KB Output is correct
4 Correct 38 ms 41448 KB Output is correct
5 Correct 38 ms 41464 KB Output is correct
6 Correct 37 ms 41464 KB Output is correct
7 Correct 37 ms 41464 KB Output is correct
8 Correct 37 ms 41464 KB Output is correct
9 Correct 38 ms 41464 KB Output is correct
10 Correct 38 ms 41464 KB Output is correct
11 Correct 37 ms 41468 KB Output is correct
12 Correct 38 ms 41464 KB Output is correct
13 Correct 38 ms 41464 KB Output is correct
14 Correct 38 ms 41464 KB Output is correct
15 Correct 39 ms 41464 KB Output is correct
16 Correct 44 ms 41464 KB Output is correct
17 Correct 43 ms 41464 KB Output is correct
18 Correct 38 ms 41464 KB Output is correct
19 Correct 38 ms 41464 KB Output is correct
20 Correct 38 ms 41464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 41464 KB Output is correct
2 Correct 37 ms 41432 KB Output is correct
3 Correct 37 ms 41456 KB Output is correct
4 Correct 38 ms 41464 KB Output is correct
5 Correct 37 ms 41464 KB Output is correct
6 Correct 37 ms 41464 KB Output is correct
7 Correct 39 ms 41464 KB Output is correct
8 Correct 37 ms 41464 KB Output is correct
9 Correct 38 ms 41464 KB Output is correct
10 Correct 37 ms 41464 KB Output is correct
11 Correct 38 ms 41464 KB Output is correct
12 Correct 37 ms 41464 KB Output is correct
13 Correct 38 ms 41468 KB Output is correct
14 Correct 38 ms 41436 KB Output is correct
15 Correct 38 ms 41468 KB Output is correct
16 Correct 38 ms 41468 KB Output is correct
17 Correct 38 ms 41464 KB Output is correct
18 Correct 38 ms 41388 KB Output is correct
19 Correct 38 ms 41336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 41592 KB Output is correct
2 Correct 44 ms 42104 KB Output is correct
3 Correct 52 ms 42076 KB Output is correct
4 Correct 139 ms 42188 KB Output is correct
5 Correct 349 ms 43000 KB Output is correct
6 Correct 59 ms 43000 KB Output is correct
7 Correct 185 ms 43000 KB Output is correct
8 Correct 38 ms 41492 KB Output is correct
9 Correct 38 ms 41464 KB Output is correct
10 Correct 38 ms 41464 KB Output is correct
11 Correct 38 ms 41436 KB Output is correct
12 Correct 38 ms 41464 KB Output is correct
13 Correct 38 ms 41500 KB Output is correct
14 Correct 59 ms 41592 KB Output is correct
15 Correct 39 ms 41596 KB Output is correct
16 Correct 45 ms 41796 KB Output is correct
17 Correct 45 ms 42104 KB Output is correct
18 Correct 50 ms 42104 KB Output is correct
19 Correct 112 ms 42104 KB Output is correct
20 Correct 250 ms 42872 KB Output is correct
21 Correct 58 ms 42872 KB Output is correct
22 Correct 141 ms 42924 KB Output is correct
23 Correct 54 ms 42872 KB Output is correct
24 Correct 70 ms 42872 KB Output is correct
25 Correct 252 ms 42944 KB Output is correct
26 Correct 38 ms 41464 KB Output is correct
27 Correct 38 ms 41464 KB Output is correct
28 Correct 44 ms 41720 KB Output is correct
29 Correct 43 ms 41592 KB Output is correct
30 Correct 41 ms 41592 KB Output is correct
31 Correct 44 ms 42104 KB Output is correct
32 Correct 46 ms 42104 KB Output is correct
33 Correct 62 ms 42076 KB Output is correct
34 Correct 103 ms 42872 KB Output is correct
35 Correct 54 ms 42872 KB Output is correct
36 Correct 76 ms 42872 KB Output is correct
37 Correct 40 ms 41592 KB Output is correct
38 Correct 64 ms 41644 KB Output is correct
39 Correct 38 ms 41464 KB Output is correct
40 Correct 38 ms 41464 KB Output is correct
41 Correct 37 ms 41464 KB Output is correct
42 Correct 37 ms 41464 KB Output is correct