# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
95437 | 2019-02-01T07:28:41 Z | choikiwon | K개의 묶음 (IZhO14_blocks) | C++17 | 183 ms | 2300 KB |
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int MN = 100010; int N, K; int A[MN], dp[2][MN]; struct Info { int h, mn, id; }; int main() { 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<Info> stk1; stack<pii> stk2; for(int j = N - i; j >= 0; j--) { int mn = dp[p][j + 1]; while(!stk1.empty() && stk1.top().h <= A[j]) { mn = min(mn, stk1.top().mn); stk1.pop(); } int t = stk1.empty()? N - i + 1 : stk1.top().id; while(!stk2.empty() && stk2.top().second < t) { stk2.pop(); } stk1.push({A[j], mn, j}); if(stk2.empty() || stk2.top().first > mn + A[j]) { stk2.push({mn + A[j], j}); } dp[c][j] = stk2.top().first; //cout << i << ' ' << j << ' ' << dp[c][j] << endl; } } printf("%d", dp[K & 1][0]); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 380 KB | Output is correct |
4 | Correct | 2 ms | 388 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 0 ms | 420 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 292 KB | Output is correct |
10 | Correct | 2 ms | 420 KB | Output is correct |
11 | Correct | 2 ms | 252 KB | Output is correct |
12 | Correct | 2 ms | 256 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 376 KB | Output is correct |
16 | Correct | 2 ms | 376 KB | Output is correct |
17 | Correct | 2 ms | 256 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 2 ms | 252 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 3 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 256 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 376 KB | Output is correct |
16 | Correct | 2 ms | 376 KB | Output is correct |
17 | Correct | 2 ms | 376 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
19 | Correct | 2 ms | 256 KB | Output is correct |
20 | Correct | 2 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 420 KB | Output is correct |
4 | Correct | 0 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 1 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 256 KB | Output is correct |
11 | Correct | 2 ms | 380 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 256 KB | Output is correct |
16 | Correct | 2 ms | 256 KB | Output is correct |
17 | Correct | 2 ms | 256 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
19 | Correct | 2 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 504 KB | Output is correct |
2 | Correct | 7 ms | 632 KB | Output is correct |
3 | Correct | 12 ms | 1196 KB | Output is correct |
4 | Correct | 63 ms | 1220 KB | Output is correct |
5 | Correct | 183 ms | 2300 KB | Output is correct |
6 | Correct | 18 ms | 2212 KB | Output is correct |
7 | Correct | 88 ms | 2288 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 2 ms | 256 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 18 ms | 508 KB | Output is correct |
15 | Correct | 3 ms | 504 KB | Output is correct |
16 | Correct | 7 ms | 504 KB | Output is correct |
17 | Correct | 7 ms | 632 KB | Output is correct |
18 | Correct | 11 ms | 888 KB | Output is correct |
19 | Correct | 62 ms | 888 KB | Output is correct |
20 | Correct | 166 ms | 1532 KB | Output is correct |
21 | Correct | 18 ms | 1528 KB | Output is correct |
22 | Correct | 82 ms | 1528 KB | Output is correct |
23 | Correct | 14 ms | 1144 KB | Output is correct |
24 | Correct | 28 ms | 1656 KB | Output is correct |
25 | Correct | 165 ms | 1528 KB | Output is correct |
26 | Correct | 2 ms | 376 KB | Output is correct |
27 | Correct | 2 ms | 376 KB | Output is correct |
28 | Correct | 13 ms | 504 KB | Output is correct |
29 | Correct | 3 ms | 504 KB | Output is correct |
30 | Correct | 11 ms | 376 KB | Output is correct |
31 | Correct | 6 ms | 632 KB | Output is correct |
32 | Correct | 10 ms | 888 KB | Output is correct |
33 | Correct | 42 ms | 888 KB | Output is correct |
34 | Correct | 119 ms | 1528 KB | Output is correct |
35 | Correct | 15 ms | 1532 KB | Output is correct |
36 | Correct | 59 ms | 1528 KB | Output is correct |
37 | Correct | 3 ms | 504 KB | Output is correct |
38 | Correct | 17 ms | 560 KB | Output is correct |
39 | Correct | 2 ms | 376 KB | Output is correct |
40 | Correct | 2 ms | 376 KB | Output is correct |
41 | Correct | 2 ms | 376 KB | Output is correct |
42 | Correct | 2 ms | 376 KB | Output is correct |