답안 #678027

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
678027 2023-01-05T03:48:40 Z TS_2392 K개의 묶음 (IZhO14_blocks) C++14
100 / 100
181 ms 41192 KB
#include <bits/stdc++.h>
#define fileIO(name) if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);}
#define SPEED ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define rall(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()
#define sqr(x) (x) * (x)

#define eb emplace_back
#define epl emplace

#define lwb lower_bound
#define upb upper_bound

#define mp make_pair
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;

typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;

template<class T1, class T2> bool minimize(T1 &a, T2 b){
    return a > b ? a = b, true : false;
}
template<class T1, class T2> bool maximize(T1 &a, T2 b){
    return a < b ? a = b, true : false;
}
const int N = 1e5 + 1, K = 101, oo = 1e9 + 10;
int n, k, a[N], dp[K][N];
int main(){
    //SPEED;
    cin >> n >> k;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    memset(dp, 0x3f, sizeof dp);
    dp[1][0] = 0;
    for (int i = 1; i <= n; ++i) dp[1][i] = max(dp[1][i - 1], a[i]);
    for(int i = 2; i <= k; ++i){
        stack<pii> stk;
        for(int j = i; j <= n; ++j){
            int MinPrevF = dp[i - 1][j - 1];
            while(!stk.empty() && a[stk.top().fi] <= a[j]){
                minimize(MinPrevF, stk.top().se);
                stk.pop();
            }
            dp[i][j] = min(dp[i][stk.empty() ? 0 : stk.top().fi], MinPrevF + a[j]);
            stk.push({j, MinPrevF});
        }
    }
    cout << dp[k][n];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 39768 KB Output is correct
2 Correct 15 ms 39712 KB Output is correct
3 Correct 16 ms 39764 KB Output is correct
4 Correct 15 ms 39764 KB Output is correct
5 Correct 16 ms 39764 KB Output is correct
6 Correct 18 ms 39824 KB Output is correct
7 Correct 17 ms 39724 KB Output is correct
8 Correct 16 ms 39764 KB Output is correct
9 Correct 17 ms 39736 KB Output is correct
10 Correct 17 ms 39792 KB Output is correct
11 Correct 17 ms 39764 KB Output is correct
12 Correct 18 ms 39764 KB Output is correct
13 Correct 16 ms 39764 KB Output is correct
14 Correct 18 ms 39764 KB Output is correct
15 Correct 16 ms 39764 KB Output is correct
16 Correct 16 ms 39752 KB Output is correct
17 Correct 16 ms 39752 KB Output is correct
18 Correct 16 ms 39840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 39812 KB Output is correct
2 Correct 16 ms 39764 KB Output is correct
3 Correct 16 ms 39744 KB Output is correct
4 Correct 16 ms 39744 KB Output is correct
5 Correct 20 ms 39776 KB Output is correct
6 Correct 17 ms 39808 KB Output is correct
7 Correct 19 ms 39752 KB Output is correct
8 Correct 16 ms 39736 KB Output is correct
9 Correct 17 ms 39764 KB Output is correct
10 Correct 16 ms 39796 KB Output is correct
11 Correct 16 ms 39764 KB Output is correct
12 Correct 16 ms 39784 KB Output is correct
13 Correct 16 ms 39740 KB Output is correct
14 Correct 16 ms 39756 KB Output is correct
15 Correct 15 ms 39764 KB Output is correct
16 Correct 16 ms 39804 KB Output is correct
17 Correct 17 ms 39764 KB Output is correct
18 Correct 20 ms 39764 KB Output is correct
19 Correct 21 ms 39732 KB Output is correct
20 Correct 17 ms 39816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 39768 KB Output is correct
2 Correct 15 ms 39712 KB Output is correct
3 Correct 16 ms 39764 KB Output is correct
4 Correct 15 ms 39764 KB Output is correct
5 Correct 16 ms 39764 KB Output is correct
6 Correct 18 ms 39824 KB Output is correct
7 Correct 17 ms 39724 KB Output is correct
8 Correct 16 ms 39764 KB Output is correct
9 Correct 17 ms 39736 KB Output is correct
10 Correct 17 ms 39792 KB Output is correct
11 Correct 17 ms 39764 KB Output is correct
12 Correct 18 ms 39764 KB Output is correct
13 Correct 16 ms 39764 KB Output is correct
14 Correct 18 ms 39764 KB Output is correct
15 Correct 16 ms 39764 KB Output is correct
16 Correct 16 ms 39752 KB Output is correct
17 Correct 16 ms 39752 KB Output is correct
18 Correct 16 ms 39840 KB Output is correct
19 Correct 16 ms 39812 KB Output is correct
20 Correct 16 ms 39764 KB Output is correct
21 Correct 16 ms 39744 KB Output is correct
22 Correct 16 ms 39744 KB Output is correct
23 Correct 20 ms 39776 KB Output is correct
24 Correct 17 ms 39808 KB Output is correct
25 Correct 19 ms 39752 KB Output is correct
26 Correct 16 ms 39736 KB Output is correct
27 Correct 17 ms 39764 KB Output is correct
28 Correct 16 ms 39796 KB Output is correct
29 Correct 16 ms 39764 KB Output is correct
30 Correct 16 ms 39784 KB Output is correct
31 Correct 16 ms 39740 KB Output is correct
32 Correct 16 ms 39756 KB Output is correct
33 Correct 15 ms 39764 KB Output is correct
34 Correct 16 ms 39804 KB Output is correct
35 Correct 17 ms 39764 KB Output is correct
36 Correct 20 ms 39764 KB Output is correct
37 Correct 21 ms 39732 KB Output is correct
38 Correct 17 ms 39816 KB Output is correct
39 Correct 17 ms 39788 KB Output is correct
40 Correct 16 ms 39844 KB Output is correct
41 Correct 16 ms 39776 KB Output is correct
42 Correct 16 ms 39768 KB Output is correct
43 Correct 16 ms 39764 KB Output is correct
44 Correct 17 ms 39748 KB Output is correct
45 Correct 16 ms 39836 KB Output is correct
46 Correct 18 ms 39784 KB Output is correct
47 Correct 16 ms 39764 KB Output is correct
48 Correct 19 ms 39764 KB Output is correct
49 Correct 17 ms 39788 KB Output is correct
50 Correct 18 ms 39792 KB Output is correct
51 Correct 19 ms 39696 KB Output is correct
52 Correct 16 ms 39764 KB Output is correct
53 Correct 17 ms 39732 KB Output is correct
54 Correct 16 ms 39764 KB Output is correct
55 Correct 16 ms 39772 KB Output is correct
56 Correct 16 ms 39792 KB Output is correct
57 Correct 16 ms 39776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 39768 KB Output is correct
2 Correct 15 ms 39712 KB Output is correct
3 Correct 16 ms 39764 KB Output is correct
4 Correct 15 ms 39764 KB Output is correct
5 Correct 16 ms 39764 KB Output is correct
6 Correct 18 ms 39824 KB Output is correct
7 Correct 17 ms 39724 KB Output is correct
8 Correct 16 ms 39764 KB Output is correct
9 Correct 17 ms 39736 KB Output is correct
10 Correct 17 ms 39792 KB Output is correct
11 Correct 17 ms 39764 KB Output is correct
12 Correct 18 ms 39764 KB Output is correct
13 Correct 16 ms 39764 KB Output is correct
14 Correct 18 ms 39764 KB Output is correct
15 Correct 16 ms 39764 KB Output is correct
16 Correct 16 ms 39752 KB Output is correct
17 Correct 16 ms 39752 KB Output is correct
18 Correct 16 ms 39840 KB Output is correct
19 Correct 16 ms 39812 KB Output is correct
20 Correct 16 ms 39764 KB Output is correct
21 Correct 16 ms 39744 KB Output is correct
22 Correct 16 ms 39744 KB Output is correct
23 Correct 20 ms 39776 KB Output is correct
24 Correct 17 ms 39808 KB Output is correct
25 Correct 19 ms 39752 KB Output is correct
26 Correct 16 ms 39736 KB Output is correct
27 Correct 17 ms 39764 KB Output is correct
28 Correct 16 ms 39796 KB Output is correct
29 Correct 16 ms 39764 KB Output is correct
30 Correct 16 ms 39784 KB Output is correct
31 Correct 16 ms 39740 KB Output is correct
32 Correct 16 ms 39756 KB Output is correct
33 Correct 15 ms 39764 KB Output is correct
34 Correct 16 ms 39804 KB Output is correct
35 Correct 17 ms 39764 KB Output is correct
36 Correct 20 ms 39764 KB Output is correct
37 Correct 21 ms 39732 KB Output is correct
38 Correct 17 ms 39816 KB Output is correct
39 Correct 17 ms 39788 KB Output is correct
40 Correct 16 ms 39844 KB Output is correct
41 Correct 16 ms 39776 KB Output is correct
42 Correct 16 ms 39768 KB Output is correct
43 Correct 16 ms 39764 KB Output is correct
44 Correct 17 ms 39748 KB Output is correct
45 Correct 16 ms 39836 KB Output is correct
46 Correct 18 ms 39784 KB Output is correct
47 Correct 16 ms 39764 KB Output is correct
48 Correct 19 ms 39764 KB Output is correct
49 Correct 17 ms 39788 KB Output is correct
50 Correct 18 ms 39792 KB Output is correct
51 Correct 19 ms 39696 KB Output is correct
52 Correct 16 ms 39764 KB Output is correct
53 Correct 17 ms 39732 KB Output is correct
54 Correct 16 ms 39764 KB Output is correct
55 Correct 16 ms 39772 KB Output is correct
56 Correct 16 ms 39792 KB Output is correct
57 Correct 16 ms 39776 KB Output is correct
58 Correct 20 ms 39932 KB Output is correct
59 Correct 38 ms 40240 KB Output is correct
60 Correct 35 ms 40292 KB Output is correct
61 Correct 63 ms 40304 KB Output is correct
62 Correct 142 ms 40884 KB Output is correct
63 Correct 46 ms 40780 KB Output is correct
64 Correct 93 ms 40860 KB Output is correct
65 Correct 16 ms 39768 KB Output is correct
66 Correct 16 ms 39784 KB Output is correct
67 Correct 16 ms 39776 KB Output is correct
68 Correct 16 ms 39764 KB Output is correct
69 Correct 17 ms 39764 KB Output is correct
70 Correct 16 ms 39768 KB Output is correct
71 Correct 32 ms 39924 KB Output is correct
72 Correct 19 ms 39892 KB Output is correct
73 Correct 22 ms 39884 KB Output is correct
74 Correct 29 ms 40268 KB Output is correct
75 Correct 38 ms 40268 KB Output is correct
76 Correct 79 ms 40288 KB Output is correct
77 Correct 177 ms 40940 KB Output is correct
78 Correct 46 ms 40840 KB Output is correct
79 Correct 104 ms 40764 KB Output is correct
80 Correct 54 ms 40832 KB Output is correct
81 Correct 58 ms 40860 KB Output is correct
82 Correct 181 ms 40888 KB Output is correct
83 Correct 15 ms 39764 KB Output is correct
84 Correct 16 ms 39780 KB Output is correct
85 Correct 30 ms 39936 KB Output is correct
86 Correct 24 ms 39956 KB Output is correct
87 Correct 25 ms 39884 KB Output is correct
88 Correct 28 ms 40268 KB Output is correct
89 Correct 31 ms 40396 KB Output is correct
90 Correct 66 ms 40308 KB Output is correct
91 Correct 161 ms 41192 KB Output is correct
92 Correct 50 ms 41096 KB Output is correct
93 Correct 99 ms 41176 KB Output is correct
94 Correct 18 ms 39868 KB Output is correct
95 Correct 29 ms 39928 KB Output is correct
96 Correct 17 ms 39764 KB Output is correct
97 Correct 16 ms 39724 KB Output is correct
98 Correct 16 ms 39720 KB Output is correct
99 Correct 17 ms 39820 KB Output is correct