Submission #173982

# Submission time Handle Problem Language Result Execution time Memory
173982 2020-01-06T05:22:35 Z tourist K blocks (IZhO14_blocks) C++14
100 / 100
473 ms 85364 KB
#include <bits/stdc++.h>

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define all(s) s.begin(), s.end()

using namespace std;

const int N = 1e5 + 5;

int n, k, a[N];

long long dp[N][105];

vector <pair< pair<int, long long>, long long> > vec;

main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	memset(dp, 0x3f3f3f3f, sizeof(dp));
	dp[0][0] = 0;
	for (int j = 1; j <= k; j++) {
		vec.clear();
		for (int i = 1; i <= n; i++) {
			long long mn = dp[i - 1][j - 1];
			while (!vec.empty() && vec.back().fr.fr <= a[i]) {
				mn = min(mn, vec.back().fr.sc);
				vec.pop_back();
			}
			long long val = a[i] + mn;
			if (!vec.empty()) 
				val = min(val, vec.back().sc);
				
			vec.pb({{a[i], mn}, val});
			dp[i][j] = val;
		}
	}	
	cout << dp[n][k]<< endl;
}

Compilation message

blocks.cpp:19:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
blocks.cpp: In function 'int main()':
blocks.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 71 ms 82552 KB Output is correct
2 Correct 70 ms 82552 KB Output is correct
3 Correct 71 ms 82552 KB Output is correct
4 Correct 71 ms 82552 KB Output is correct
5 Correct 70 ms 82552 KB Output is correct
6 Correct 70 ms 82472 KB Output is correct
7 Correct 70 ms 82552 KB Output is correct
8 Correct 72 ms 82552 KB Output is correct
9 Correct 70 ms 82552 KB Output is correct
10 Correct 71 ms 82524 KB Output is correct
11 Correct 70 ms 82552 KB Output is correct
12 Correct 70 ms 82552 KB Output is correct
13 Correct 70 ms 82524 KB Output is correct
14 Correct 70 ms 82468 KB Output is correct
15 Correct 70 ms 82552 KB Output is correct
16 Correct 70 ms 82552 KB Output is correct
17 Correct 70 ms 82488 KB Output is correct
18 Correct 70 ms 82552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 82508 KB Output is correct
2 Correct 70 ms 82528 KB Output is correct
3 Correct 70 ms 82556 KB Output is correct
4 Correct 70 ms 82540 KB Output is correct
5 Correct 70 ms 82552 KB Output is correct
6 Correct 69 ms 82552 KB Output is correct
7 Correct 69 ms 82516 KB Output is correct
8 Correct 70 ms 82552 KB Output is correct
9 Correct 70 ms 82552 KB Output is correct
10 Correct 70 ms 82552 KB Output is correct
11 Correct 71 ms 82456 KB Output is correct
12 Correct 70 ms 82524 KB Output is correct
13 Correct 70 ms 82548 KB Output is correct
14 Correct 70 ms 82552 KB Output is correct
15 Correct 70 ms 82488 KB Output is correct
16 Correct 70 ms 82552 KB Output is correct
17 Correct 70 ms 82544 KB Output is correct
18 Correct 73 ms 82552 KB Output is correct
19 Correct 70 ms 82552 KB Output is correct
20 Correct 70 ms 82552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 82444 KB Output is correct
2 Correct 72 ms 82552 KB Output is correct
3 Correct 70 ms 82600 KB Output is correct
4 Correct 70 ms 82552 KB Output is correct
5 Correct 70 ms 82552 KB Output is correct
6 Correct 70 ms 82552 KB Output is correct
7 Correct 70 ms 82592 KB Output is correct
8 Correct 70 ms 82552 KB Output is correct
9 Correct 70 ms 82552 KB Output is correct
10 Correct 70 ms 82552 KB Output is correct
11 Correct 69 ms 82524 KB Output is correct
12 Correct 70 ms 82552 KB Output is correct
13 Correct 70 ms 82552 KB Output is correct
14 Correct 71 ms 82552 KB Output is correct
15 Correct 71 ms 82552 KB Output is correct
16 Correct 70 ms 82552 KB Output is correct
17 Correct 70 ms 82536 KB Output is correct
18 Correct 70 ms 82632 KB Output is correct
19 Correct 70 ms 82552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 82552 KB Output is correct
2 Correct 77 ms 83064 KB Output is correct
3 Correct 86 ms 83000 KB Output is correct
4 Correct 184 ms 83164 KB Output is correct
5 Correct 473 ms 83576 KB Output is correct
6 Correct 94 ms 83576 KB Output is correct
7 Correct 317 ms 83576 KB Output is correct
8 Correct 70 ms 82556 KB Output is correct
9 Correct 71 ms 82552 KB Output is correct
10 Correct 71 ms 82552 KB Output is correct
11 Correct 70 ms 82552 KB Output is correct
12 Correct 70 ms 82528 KB Output is correct
13 Correct 70 ms 82472 KB Output is correct
14 Correct 104 ms 82616 KB Output is correct
15 Correct 72 ms 82684 KB Output is correct
16 Correct 79 ms 82680 KB Output is correct
17 Correct 78 ms 82948 KB Output is correct
18 Correct 87 ms 83064 KB Output is correct
19 Correct 191 ms 82936 KB Output is correct
20 Correct 450 ms 83704 KB Output is correct
21 Correct 95 ms 83576 KB Output is correct
22 Correct 248 ms 83576 KB Output is correct
23 Correct 88 ms 83576 KB Output is correct
24 Correct 122 ms 83576 KB Output is correct
25 Correct 435 ms 83680 KB Output is correct
26 Correct 70 ms 82552 KB Output is correct
27 Correct 71 ms 82684 KB Output is correct
28 Correct 119 ms 82808 KB Output is correct
29 Correct 72 ms 82808 KB Output is correct
30 Correct 80 ms 82908 KB Output is correct
31 Correct 78 ms 83568 KB Output is correct
32 Correct 86 ms 83512 KB Output is correct
33 Correct 185 ms 83572 KB Output is correct
34 Correct 414 ms 85364 KB Output is correct
35 Correct 95 ms 85228 KB Output is correct
36 Correct 228 ms 85208 KB Output is correct
37 Correct 72 ms 82680 KB Output is correct
38 Correct 100 ms 82552 KB Output is correct
39 Correct 71 ms 82552 KB Output is correct
40 Correct 71 ms 82552 KB Output is correct
41 Correct 70 ms 82488 KB Output is correct
42 Correct 70 ms 82552 KB Output is correct