# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
25526 | 2017-06-22T22:19:17 Z | Bruteforceman | K blocks (IZhO14_blocks) | C++11 | 206 ms | 85760 KB |
#include "bits/stdc++.h" using namespace std; int a[100010]; long long dp[105][100005]; const long long inf = 1e15; struct data { int val; long long dp, maxn; data (int val, long long dp, long long maxn) { this -> val = val; this -> dp = dp; this -> maxn = maxn; } data () {} }; long long helpHRSiam(int N, int K, int A[]) { for(int i = 1; i <= N; i++) { a[i] = A[i-1]; } memset(dp, 0, sizeof dp); dp[0][0] = 0; for(int i = 1; i <= N; i++) { dp[0][i] = inf; } for(int i = 1; i <= K; i++) { dp[i][0] = inf; stack <data> Q; for(int j = 1; j <= N; j++) { data x; x.val = a[j]; x.dp = dp[i - 1][j - 1]; while(!Q.empty() and Q.top().val <= a[j]) { x.dp = min(Q.top().dp, x.dp); Q.pop(); } x.maxn = x.dp + x.val; if(!Q.empty()) x.maxn = min(x.maxn, Q.top().maxn); Q.push(x); dp[i][j] = Q.top().maxn; } } return dp[K][N]; } int main(int argc, char const *argv[]) { int N, K; scanf("%d %d", &N, &K); int *A; A = new int [N]; for(int i = 0; i < N; i++) { scanf("%d", &A[i]); } printf("%lld\n", helpHRSiam(N, K, A)); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 84448 KB | Output is correct |
2 | Correct | 6 ms | 84448 KB | Output is correct |
3 | Correct | 3 ms | 84448 KB | Output is correct |
4 | Correct | 3 ms | 84448 KB | Output is correct |
5 | Correct | 0 ms | 84448 KB | Output is correct |
6 | Correct | 3 ms | 84448 KB | Output is correct |
7 | Correct | 6 ms | 84448 KB | Output is correct |
8 | Correct | 6 ms | 84448 KB | Output is correct |
9 | Correct | 3 ms | 84448 KB | Output is correct |
10 | Correct | 6 ms | 84448 KB | Output is correct |
11 | Correct | 6 ms | 84448 KB | Output is correct |
12 | Correct | 6 ms | 84448 KB | Output is correct |
13 | Correct | 6 ms | 84448 KB | Output is correct |
14 | Correct | 6 ms | 84448 KB | Output is correct |
15 | Correct | 6 ms | 84448 KB | Output is correct |
16 | Correct | 3 ms | 84448 KB | Output is correct |
17 | Correct | 3 ms | 84448 KB | Output is correct |
18 | Correct | 3 ms | 84448 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 84448 KB | Output is correct |
2 | Correct | 9 ms | 84448 KB | Output is correct |
3 | Correct | 0 ms | 84448 KB | Output is correct |
4 | Correct | 6 ms | 84448 KB | Output is correct |
5 | Correct | 9 ms | 84448 KB | Output is correct |
6 | Correct | 6 ms | 84448 KB | Output is correct |
7 | Correct | 6 ms | 84448 KB | Output is correct |
8 | Correct | 0 ms | 84448 KB | Output is correct |
9 | Correct | 6 ms | 84448 KB | Output is correct |
10 | Correct | 0 ms | 84448 KB | Output is correct |
11 | Correct | 6 ms | 84448 KB | Output is correct |
12 | Correct | 6 ms | 84448 KB | Output is correct |
13 | Correct | 6 ms | 84448 KB | Output is correct |
14 | Correct | 6 ms | 84448 KB | Output is correct |
15 | Correct | 6 ms | 84448 KB | Output is correct |
16 | Correct | 0 ms | 84448 KB | Output is correct |
17 | Correct | 0 ms | 84448 KB | Output is correct |
18 | Correct | 6 ms | 84448 KB | Output is correct |
19 | Correct | 9 ms | 84448 KB | Output is correct |
20 | Correct | 6 ms | 84448 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 84448 KB | Output is correct |
2 | Correct | 6 ms | 84448 KB | Output is correct |
3 | Correct | 0 ms | 84448 KB | Output is correct |
4 | Correct | 6 ms | 84448 KB | Output is correct |
5 | Correct | 3 ms | 84448 KB | Output is correct |
6 | Correct | 9 ms | 84448 KB | Output is correct |
7 | Correct | 6 ms | 84448 KB | Output is correct |
8 | Correct | 13 ms | 84448 KB | Output is correct |
9 | Correct | 6 ms | 84448 KB | Output is correct |
10 | Correct | 3 ms | 84448 KB | Output is correct |
11 | Correct | 9 ms | 84448 KB | Output is correct |
12 | Correct | 6 ms | 84448 KB | Output is correct |
13 | Correct | 6 ms | 84448 KB | Output is correct |
14 | Correct | 0 ms | 84448 KB | Output is correct |
15 | Correct | 6 ms | 84448 KB | Output is correct |
16 | Correct | 6 ms | 84448 KB | Output is correct |
17 | Correct | 6 ms | 84448 KB | Output is correct |
18 | Correct | 0 ms | 84448 KB | Output is correct |
19 | Correct | 3 ms | 84448 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 84448 KB | Output is correct |
2 | Correct | 13 ms | 84624 KB | Output is correct |
3 | Correct | 16 ms | 84624 KB | Output is correct |
4 | Correct | 49 ms | 84624 KB | Output is correct |
5 | Correct | 146 ms | 84840 KB | Output is correct |
6 | Correct | 33 ms | 84840 KB | Output is correct |
7 | Correct | 86 ms | 84840 KB | Output is correct |
8 | Correct | 16 ms | 84448 KB | Output is correct |
9 | Correct | 6 ms | 84448 KB | Output is correct |
10 | Correct | 16 ms | 84448 KB | Output is correct |
11 | Correct | 6 ms | 84448 KB | Output is correct |
12 | Correct | 9 ms | 84448 KB | Output is correct |
13 | Correct | 3 ms | 84448 KB | Output is correct |
14 | Correct | 23 ms | 84448 KB | Output is correct |
15 | Correct | 9 ms | 84448 KB | Output is correct |
16 | Correct | 9 ms | 84448 KB | Output is correct |
17 | Correct | 23 ms | 84624 KB | Output is correct |
18 | Correct | 26 ms | 84624 KB | Output is correct |
19 | Correct | 53 ms | 84624 KB | Output is correct |
20 | Correct | 163 ms | 84840 KB | Output is correct |
21 | Correct | 39 ms | 84840 KB | Output is correct |
22 | Correct | 123 ms | 84840 KB | Output is correct |
23 | Correct | 26 ms | 84840 KB | Output is correct |
24 | Correct | 43 ms | 84840 KB | Output is correct |
25 | Correct | 163 ms | 84840 KB | Output is correct |
26 | Correct | 9 ms | 84448 KB | Output is correct |
27 | Correct | 6 ms | 84448 KB | Output is correct |
28 | Correct | 26 ms | 84580 KB | Output is correct |
29 | Correct | 9 ms | 84580 KB | Output is correct |
30 | Correct | 9 ms | 84580 KB | Output is correct |
31 | Correct | 16 ms | 85016 KB | Output is correct |
32 | Correct | 16 ms | 85012 KB | Output is correct |
33 | Correct | 66 ms | 85012 KB | Output is correct |
34 | Correct | 206 ms | 85760 KB | Output is correct |
35 | Correct | 29 ms | 85760 KB | Output is correct |
36 | Correct | 93 ms | 85760 KB | Output is correct |
37 | Correct | 3 ms | 84448 KB | Output is correct |
38 | Correct | 33 ms | 84448 KB | Output is correct |
39 | Correct | 13 ms | 84448 KB | Output is correct |
40 | Correct | 9 ms | 84448 KB | Output is correct |
41 | Correct | 0 ms | 84448 KB | Output is correct |
42 | Correct | 6 ms | 84448 KB | Output is correct |