Submission #158338

# Submission time Handle Problem Language Result Execution time Memory
158338 2019-10-16T13:54:09 Z gemini_man K blocks (IZhO14_blocks) C++11
100 / 100
628 ms 85796 KB
#include <bits/stdc++.h>
#define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i))
#define down(i,b,a) for(int (i) = (b);i>=(a);--i)
#define debug(x) cerr << (x) << '\n';
#define bits(x,i) ((x >> i) & 1)
using namespace std;
#define int long long
const int N = 100005;
const int K = 105;
const int INF = 2e9;
int n,k;
int dp[N][K];
int a[N];
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	// freopen("BLOCKS_IZHO.inp", "r", stdin);
	// freopen("BLOCKS_IZHO.out", "w", stdout);
	cin >> n >> k;
	up(i,1,n) cin >> a[i];
	int curMax = 0;
	memset(dp, 0x3f, sizeof(dp));
	dp[0][1] = 0;
	up(i,1,n)	dp[i][1] = max(dp[i-1][1], a[i]);
	for(int j = 2; j <= k ;++j){
		vector< pair<int,int> > sk;	
		for( int i = j;i <= n;++i){
			int minF = dp[i-1][j-1];
			// first = value
			// second = id
			while (!sk.empty() && a[sk.back().second] <= a[i]){
				minF = min (minF, sk.back().first);
				sk.pop_back();
			}
			dp[i][j] = min(dp[sk.empty() ? 0 : sk.back().second][j], minF + a[i]);
			sk.push_back(pair<int,int> (minF, i));
		}
	}
	cout << dp[n][k];
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:20:6: warning: unused variable 'curMax' [-Wunused-variable]
  int curMax = 0;
      ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 69 ms 82552 KB Output is correct
2 Correct 69 ms 82524 KB Output is correct
3 Correct 70 ms 82544 KB Output is correct
4 Correct 70 ms 82576 KB Output is correct
5 Correct 69 ms 82552 KB Output is correct
6 Correct 69 ms 82588 KB Output is correct
7 Correct 71 ms 82628 KB Output is correct
8 Correct 70 ms 82524 KB Output is correct
9 Correct 70 ms 82484 KB Output is correct
10 Correct 70 ms 82552 KB Output is correct
11 Correct 75 ms 82676 KB Output is correct
12 Correct 70 ms 82552 KB Output is correct
13 Correct 78 ms 82596 KB Output is correct
14 Correct 69 ms 82552 KB Output is correct
15 Correct 70 ms 82552 KB Output is correct
16 Correct 83 ms 82524 KB Output is correct
17 Correct 70 ms 82552 KB Output is correct
18 Correct 82 ms 82524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 82480 KB Output is correct
2 Correct 76 ms 82552 KB Output is correct
3 Correct 70 ms 82552 KB Output is correct
4 Correct 70 ms 82592 KB Output is correct
5 Correct 70 ms 82552 KB Output is correct
6 Correct 70 ms 82532 KB Output is correct
7 Correct 71 ms 82552 KB Output is correct
8 Correct 69 ms 82552 KB Output is correct
9 Correct 69 ms 82496 KB Output is correct
10 Correct 70 ms 82524 KB Output is correct
11 Correct 71 ms 82552 KB Output is correct
12 Correct 70 ms 82552 KB Output is correct
13 Correct 70 ms 82552 KB Output is correct
14 Correct 70 ms 82552 KB Output is correct
15 Correct 70 ms 82524 KB Output is correct
16 Correct 70 ms 82552 KB Output is correct
17 Correct 70 ms 82564 KB Output is correct
18 Correct 70 ms 82552 KB Output is correct
19 Correct 69 ms 82524 KB Output is correct
20 Correct 70 ms 82524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 82552 KB Output is correct
2 Correct 70 ms 82560 KB Output is correct
3 Correct 70 ms 82516 KB Output is correct
4 Correct 69 ms 82552 KB Output is correct
5 Correct 70 ms 82592 KB Output is correct
6 Correct 70 ms 82552 KB Output is correct
7 Correct 69 ms 82552 KB Output is correct
8 Correct 70 ms 82640 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 82552 KB Output is correct
12 Correct 70 ms 82552 KB Output is correct
13 Correct 70 ms 82632 KB Output is correct
14 Correct 70 ms 82552 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 82524 KB Output is correct
18 Correct 70 ms 82552 KB Output is correct
19 Correct 70 ms 82484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 82628 KB Output is correct
2 Correct 76 ms 83224 KB Output is correct
3 Correct 85 ms 83164 KB Output is correct
4 Correct 175 ms 83192 KB Output is correct
5 Correct 452 ms 84180 KB Output is correct
6 Correct 89 ms 83960 KB Output is correct
7 Correct 231 ms 84000 KB Output is correct
8 Correct 70 ms 82552 KB Output is correct
9 Correct 71 ms 82484 KB Output is correct
10 Correct 71 ms 82552 KB Output is correct
11 Correct 70 ms 82552 KB Output is correct
12 Correct 71 ms 82556 KB Output is correct
13 Correct 71 ms 82692 KB Output is correct
14 Correct 103 ms 82680 KB Output is correct
15 Correct 72 ms 82668 KB Output is correct
16 Correct 79 ms 82736 KB Output is correct
17 Correct 76 ms 83192 KB Output is correct
18 Correct 86 ms 83204 KB Output is correct
19 Correct 191 ms 83268 KB Output is correct
20 Correct 449 ms 83960 KB Output is correct
21 Correct 91 ms 83960 KB Output is correct
22 Correct 244 ms 84060 KB Output is correct
23 Correct 83 ms 83960 KB Output is correct
24 Correct 115 ms 84088 KB Output is correct
25 Correct 425 ms 83960 KB Output is correct
26 Correct 70 ms 82552 KB Output is correct
27 Correct 70 ms 82552 KB Output is correct
28 Correct 99 ms 82828 KB Output is correct
29 Correct 71 ms 82780 KB Output is correct
30 Correct 78 ms 82680 KB Output is correct
31 Correct 75 ms 83208 KB Output is correct
32 Correct 86 ms 83780 KB Output is correct
33 Correct 193 ms 83732 KB Output is correct
34 Correct 628 ms 85652 KB Output is correct
35 Correct 92 ms 85664 KB Output is correct
36 Correct 284 ms 85796 KB Output is correct
37 Correct 72 ms 82680 KB Output is correct
38 Correct 100 ms 82652 KB Output is correct
39 Correct 70 ms 82552 KB Output is correct
40 Correct 70 ms 82680 KB Output is correct
41 Correct 70 ms 82524 KB Output is correct
42 Correct 70 ms 82556 KB Output is correct