Submission #146384

# Submission time Handle Problem Language Result Execution time Memory
146384 2019-08-23T16:14:34 Z abacaba K blocks (IZhO14_blocks) C++14
100 / 100
240 ms 2028 KB
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <time.h>
#include <list>
#include <typeinfo>
#include <cstdio>
#include <numeric>
#include <stack>
#include <stdio.h>
using namespace std;
 
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

const int inf = 2e9;
const int N = 1e5 + 15;
const int K = 115;
int n, k, a[N], dp[2][N], maxx;
stack <int> s[2];

int main() {
	for(int i = 0; i < 2; ++i)
		for(int j = 0; j < N; ++j)
			dp[i][j] = inf;
	cin >> n >> k;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
		maxx = max(maxx, a[i]);
		dp[1][i] = maxx;
	}
	for(int i = 2; i <= k; ++i) {
		while(!s[0].empty())
			s[0].pop(), s[1].pop();
		for(int j = 0; j < N; ++j)
			dp[i & 1][j] = inf;
		for(int j = 1; j <= n; ++j) {
			int cur = dp[(i - 1) & 1][j - 1];
			while(!s[0].empty() && s[0].top() < a[j]) {
				cur = min(cur, s[1].top());
				s[0].pop(), s[1].pop();
			}
			if(s[0].empty() || s[0].top() + s[1].top() > cur + a[j])
				s[0].push(a[j]), s[1].push(cur);

			if(j >= i)
				dp[i & 1][j] = s[0].top() + s[1].top();
		}
	}
	cout << dp[k & 1][n] << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 3 ms 1144 KB Output is correct
10 Correct 3 ms 1148 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1144 KB Output is correct
13 Correct 3 ms 1144 KB Output is correct
14 Correct 3 ms 1144 KB Output is correct
15 Correct 3 ms 1144 KB Output is correct
16 Correct 3 ms 1144 KB Output is correct
17 Correct 3 ms 1144 KB Output is correct
18 Correct 3 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1148 KB Output is correct
3 Correct 4 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 1 ms 1144 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 3 ms 1144 KB Output is correct
10 Correct 3 ms 1144 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1144 KB Output is correct
13 Correct 3 ms 1060 KB Output is correct
14 Correct 3 ms 1144 KB Output is correct
15 Correct 3 ms 1172 KB Output is correct
16 Correct 4 ms 1144 KB Output is correct
17 Correct 4 ms 1144 KB Output is correct
18 Correct 3 ms 1144 KB Output is correct
19 Correct 4 ms 1144 KB Output is correct
20 Correct 4 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 4 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 3 ms 1148 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 3 ms 1144 KB Output is correct
10 Correct 3 ms 1148 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1144 KB Output is correct
13 Correct 4 ms 1144 KB Output is correct
14 Correct 4 ms 1144 KB Output is correct
15 Correct 8 ms 1144 KB Output is correct
16 Correct 8 ms 1144 KB Output is correct
17 Correct 6 ms 1144 KB Output is correct
18 Correct 9 ms 1144 KB Output is correct
19 Correct 8 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1144 KB Output is correct
2 Correct 28 ms 1272 KB Output is correct
3 Correct 31 ms 1272 KB Output is correct
4 Correct 68 ms 1400 KB Output is correct
5 Correct 169 ms 1572 KB Output is correct
6 Correct 61 ms 1528 KB Output is correct
7 Correct 108 ms 1528 KB Output is correct
8 Correct 4 ms 1144 KB Output is correct
9 Correct 5 ms 1144 KB Output is correct
10 Correct 5 ms 1144 KB Output is correct
11 Correct 6 ms 1144 KB Output is correct
12 Correct 3 ms 1144 KB Output is correct
13 Correct 4 ms 1144 KB Output is correct
14 Correct 26 ms 1148 KB Output is correct
15 Correct 8 ms 1144 KB Output is correct
16 Correct 12 ms 1144 KB Output is correct
17 Correct 27 ms 1272 KB Output is correct
18 Correct 31 ms 1276 KB Output is correct
19 Correct 65 ms 1272 KB Output is correct
20 Correct 155 ms 1528 KB Output is correct
21 Correct 61 ms 1500 KB Output is correct
22 Correct 102 ms 1528 KB Output is correct
23 Correct 59 ms 1532 KB Output is correct
24 Correct 72 ms 1528 KB Output is correct
25 Correct 162 ms 1528 KB Output is correct
26 Correct 3 ms 1148 KB Output is correct
27 Correct 4 ms 1144 KB Output is correct
28 Correct 31 ms 1144 KB Output is correct
29 Correct 9 ms 1144 KB Output is correct
30 Correct 15 ms 1272 KB Output is correct
31 Correct 28 ms 1272 KB Output is correct
32 Correct 35 ms 1372 KB Output is correct
33 Correct 90 ms 1400 KB Output is correct
34 Correct 240 ms 2028 KB Output is correct
35 Correct 64 ms 1784 KB Output is correct
36 Correct 138 ms 1784 KB Output is correct
37 Correct 9 ms 1144 KB Output is correct
38 Correct 26 ms 1144 KB Output is correct
39 Correct 4 ms 1144 KB Output is correct
40 Correct 3 ms 1144 KB Output is correct
41 Correct 3 ms 1144 KB Output is correct
42 Correct 3 ms 1144 KB Output is correct