답안 #95436

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
95436 2019-02-01T07:26:16 Z choikiwon K개의 묶음 (IZhO14_blocks) C++17
100 / 100
178 ms 3480 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], dp[2][MN];

struct Info {
    int h, mn, id;
};

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<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

blocks.cpp: In function 'int main()':
blocks.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &N, &K);
     ~~~~~^~~~~~~~~~~~~~~~~
blocks.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &A[i]);
         ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 3 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 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 760 KB Output is correct
11 Correct 2 ms 760 KB Output is correct
12 Correct 2 ms 764 KB Output is correct
13 Correct 2 ms 760 KB Output is correct
14 Correct 2 ms 760 KB Output is correct
15 Correct 2 ms 760 KB Output is correct
16 Correct 2 ms 760 KB Output is correct
17 Correct 2 ms 760 KB Output is correct
18 Correct 2 ms 760 KB Output is correct
# 결과 실행 시간 메모리 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 636 KB Output is correct
8 Correct 2 ms 760 KB Output is correct
9 Correct 2 ms 760 KB Output is correct
10 Correct 3 ms 760 KB Output is correct
11 Correct 3 ms 764 KB Output is correct
12 Correct 2 ms 760 KB Output is correct
13 Correct 2 ms 760 KB Output is correct
14 Correct 2 ms 760 KB Output is correct
15 Correct 2 ms 760 KB Output is correct
16 Correct 2 ms 764 KB Output is correct
17 Correct 2 ms 760 KB Output is correct
18 Correct 2 ms 760 KB Output is correct
19 Correct 2 ms 760 KB Output is correct
20 Correct 2 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 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 760 KB Output is correct
8 Correct 3 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 Correct 2 ms 760 KB Output is correct
12 Correct 2 ms 760 KB Output is correct
13 Correct 2 ms 760 KB Output is correct
14 Correct 2 ms 760 KB Output is correct
15 Correct 2 ms 760 KB Output is correct
16 Correct 2 ms 760 KB Output is correct
17 Correct 2 ms 760 KB Output is correct
18 Correct 2 ms 760 KB Output is correct
19 Correct 2 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1016 KB Output is correct
2 Correct 7 ms 1400 KB Output is correct
3 Correct 12 ms 1912 KB Output is correct
4 Correct 62 ms 1940 KB Output is correct
5 Correct 178 ms 3480 KB Output is correct
6 Correct 17 ms 3320 KB Output is correct
7 Correct 87 ms 3320 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 Correct 2 ms 760 KB Output is correct
12 Correct 2 ms 760 KB Output is correct
13 Correct 2 ms 760 KB Output is correct
14 Correct 20 ms 888 KB Output is correct
15 Correct 4 ms 888 KB Output is correct
16 Correct 8 ms 888 KB Output is correct
17 Correct 8 ms 1400 KB Output is correct
18 Correct 13 ms 1532 KB Output is correct
19 Correct 61 ms 1528 KB Output is correct
20 Correct 168 ms 2600 KB Output is correct
21 Correct 19 ms 2552 KB Output is correct
22 Correct 83 ms 2680 KB Output is correct
23 Correct 15 ms 2168 KB Output is correct
24 Correct 28 ms 2680 KB Output is correct
25 Correct 176 ms 2680 KB Output is correct
26 Correct 3 ms 760 KB Output is correct
27 Correct 3 ms 760 KB Output is correct
28 Correct 14 ms 888 KB Output is correct
29 Correct 4 ms 888 KB Output is correct
30 Correct 6 ms 888 KB Output is correct
31 Correct 7 ms 1400 KB Output is correct
32 Correct 11 ms 1528 KB Output is correct
33 Correct 45 ms 1532 KB Output is correct
34 Correct 117 ms 2552 KB Output is correct
35 Correct 16 ms 2552 KB Output is correct
36 Correct 60 ms 2680 KB Output is correct
37 Correct 4 ms 1020 KB Output is correct
38 Correct 17 ms 1016 KB Output is correct
39 Correct 3 ms 760 KB Output is correct
40 Correct 2 ms 760 KB Output is correct
41 Correct 2 ms 760 KB Output is correct
42 Correct 2 ms 760 KB Output is correct