# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
95433 | 2019-02-01T07:09:53 Z | choikiwon | K blocks (IZhO14_blocks) | C++17 | 11 ms | 1016 KB |
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int MN = 100010; int B[MN]; int N, K; int A[MN]; ll dp[2][MN]; int main() { int p = 0; for(int i = 1; i < MN; i++) { if(i == (1 << (p + 1))) p++; B[i] = p; } scanf("%d %d", &N, &K); for(int i = 0; i < N; i++) { scanf("%d", &A[i]); } for(int i = N - 1; i >= 0; i--) { dp[1][i] = A[i]; dp[1][i] = max(dp[1][i], dp[1][i + 1]); } for(int i = 2; i <= K; i++) { int p = (i & 1) ^ 1; int c = (i & 1); stack<pair<ll, int> > stk1, stk2; for(int j = N - i; j >= 0; j--) { while(!stk1.empty() && stk1.top().first <= A[j]) { stk1.pop(); } int t = stk1.empty()? N - i + 1 : stk1.top().second; while(!stk2.empty() && stk2.top().second < t) { stk2.pop(); } stk1.push({A[j], j}); if(stk2.empty() || stk2.top().first > dp[p][t] + A[j]) { stk2.push({dp[p][t] + A[j], j}); } dp[c][j] = stk2.top().first; } } printf("%lld", dp[K & 1][0]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 760 KB | Output is correct |
2 | Correct | 2 ms | 760 KB | Output is correct |
3 | Correct | 2 ms | 760 KB | Output is correct |
4 | Correct | 2 ms | 760 KB | Output is correct |
5 | Correct | 2 ms | 636 KB | Output is correct |
6 | Correct | 2 ms | 760 KB | Output is correct |
7 | Correct | 2 ms | 760 KB | Output is correct |
8 | Correct | 2 ms | 760 KB | Output is correct |
9 | Correct | 2 ms | 760 KB | Output is correct |
10 | Correct | 2 ms | 764 KB | Output is correct |
11 | Incorrect | 2 ms | 760 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 760 KB | Output is correct |
2 | Correct | 2 ms | 760 KB | Output is correct |
3 | Correct | 2 ms | 760 KB | Output is correct |
4 | Correct | 2 ms | 760 KB | Output is correct |
5 | Correct | 2 ms | 760 KB | Output is correct |
6 | Correct | 2 ms | 760 KB | Output is correct |
7 | Correct | 2 ms | 764 KB | Output is correct |
8 | Correct | 2 ms | 760 KB | Output is correct |
9 | Correct | 2 ms | 760 KB | Output is correct |
10 | Correct | 2 ms | 760 KB | Output is correct |
11 | Incorrect | 11 ms | 760 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 760 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 10 ms | 1016 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |