답안 #1088929

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1088929 2024-09-15T14:46:20 Z kh0i K개의 묶음 (IZhO14_blocks) C++17
100 / 100
237 ms 84180 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif

using ll = long long;
using pii = pair<int, int>;

#define F first
#define S second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll get_rand(ll l, ll r) {
    assert(l <= r);
    return uniform_int_distribution<ll> (l, r)(rng);
}

const int N = 1e5 + 3;

int n, k;
ll a[N], f[103][N];

void solve(){
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];

    memset(f, 0x3f, sizeof(f));
    f[1][1] = a[1];

    for(int i = 2; i <= n; ++i)
        f[1][i] = max(f[1][i - 1], a[i]);

    for(int j = 2; j <= k; ++j){
        vector<pair<int, ll>> st;
        for(int i = 1; i <= n; ++i){
            ll s = f[j - 1][i - 1];
            while(!st.empty() and a[st.back().F] <= a[i]){
                s = min(s, st.back().S);
                st.pop_back();
            }
            int lv = (st.empty() ? 0 : st.back().F);
            f[j][i] = min(f[j][lv], s + a[i]);
            st.push_back({i, s});
        }
    }

    cout << f[k][n];
}

int32_t main() {
    cin.tie(nullptr)->sync_with_stdio(0);
    #define task "troll"
    if(fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int test = 1;
//    cin >> test;
    for(int i = 1; i <= test; ++i){
//        cout << "Case #" << i << ": ";
        solve();
    }
    #ifdef LOCAL
        cerr << "\n[Time]: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
    #endif
    return 0;
}

Compilation message

blocks.cpp: In function 'int32_t main()':
blocks.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 80980 KB Output is correct
2 Correct 47 ms 80980 KB Output is correct
3 Correct 38 ms 80820 KB Output is correct
4 Correct 37 ms 80980 KB Output is correct
5 Correct 37 ms 81060 KB Output is correct
6 Correct 35 ms 80976 KB Output is correct
7 Correct 36 ms 80988 KB Output is correct
8 Correct 36 ms 80984 KB Output is correct
9 Correct 34 ms 80988 KB Output is correct
10 Correct 35 ms 80980 KB Output is correct
11 Correct 34 ms 80988 KB Output is correct
12 Correct 34 ms 80980 KB Output is correct
13 Correct 36 ms 80984 KB Output is correct
14 Correct 36 ms 80988 KB Output is correct
15 Correct 36 ms 80980 KB Output is correct
16 Correct 36 ms 81040 KB Output is correct
17 Correct 38 ms 80976 KB Output is correct
18 Correct 38 ms 80992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 80984 KB Output is correct
2 Correct 36 ms 80980 KB Output is correct
3 Correct 35 ms 80976 KB Output is correct
4 Correct 36 ms 80976 KB Output is correct
5 Correct 35 ms 80980 KB Output is correct
6 Correct 35 ms 80980 KB Output is correct
7 Correct 36 ms 80968 KB Output is correct
8 Correct 36 ms 80976 KB Output is correct
9 Correct 37 ms 80984 KB Output is correct
10 Correct 38 ms 80884 KB Output is correct
11 Correct 35 ms 80980 KB Output is correct
12 Correct 35 ms 80976 KB Output is correct
13 Correct 39 ms 80980 KB Output is correct
14 Correct 35 ms 80976 KB Output is correct
15 Correct 37 ms 80980 KB Output is correct
16 Correct 38 ms 80976 KB Output is correct
17 Correct 37 ms 80980 KB Output is correct
18 Correct 43 ms 80976 KB Output is correct
19 Correct 34 ms 81008 KB Output is correct
20 Correct 37 ms 80976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 80980 KB Output is correct
2 Correct 47 ms 80980 KB Output is correct
3 Correct 38 ms 80820 KB Output is correct
4 Correct 37 ms 80980 KB Output is correct
5 Correct 37 ms 81060 KB Output is correct
6 Correct 35 ms 80976 KB Output is correct
7 Correct 36 ms 80988 KB Output is correct
8 Correct 36 ms 80984 KB Output is correct
9 Correct 34 ms 80988 KB Output is correct
10 Correct 35 ms 80980 KB Output is correct
11 Correct 34 ms 80988 KB Output is correct
12 Correct 34 ms 80980 KB Output is correct
13 Correct 36 ms 80984 KB Output is correct
14 Correct 36 ms 80988 KB Output is correct
15 Correct 36 ms 80980 KB Output is correct
16 Correct 36 ms 81040 KB Output is correct
17 Correct 38 ms 80976 KB Output is correct
18 Correct 38 ms 80992 KB Output is correct
19 Correct 36 ms 80984 KB Output is correct
20 Correct 36 ms 80980 KB Output is correct
21 Correct 35 ms 80976 KB Output is correct
22 Correct 36 ms 80976 KB Output is correct
23 Correct 35 ms 80980 KB Output is correct
24 Correct 35 ms 80980 KB Output is correct
25 Correct 36 ms 80968 KB Output is correct
26 Correct 36 ms 80976 KB Output is correct
27 Correct 37 ms 80984 KB Output is correct
28 Correct 38 ms 80884 KB Output is correct
29 Correct 35 ms 80980 KB Output is correct
30 Correct 35 ms 80976 KB Output is correct
31 Correct 39 ms 80980 KB Output is correct
32 Correct 35 ms 80976 KB Output is correct
33 Correct 37 ms 80980 KB Output is correct
34 Correct 38 ms 80976 KB Output is correct
35 Correct 37 ms 80980 KB Output is correct
36 Correct 43 ms 80976 KB Output is correct
37 Correct 34 ms 81008 KB Output is correct
38 Correct 37 ms 80976 KB Output is correct
39 Correct 37 ms 80976 KB Output is correct
40 Correct 35 ms 80976 KB Output is correct
41 Correct 39 ms 80980 KB Output is correct
42 Correct 37 ms 80976 KB Output is correct
43 Correct 40 ms 80980 KB Output is correct
44 Correct 36 ms 80928 KB Output is correct
45 Correct 39 ms 80984 KB Output is correct
46 Correct 38 ms 80988 KB Output is correct
47 Correct 39 ms 81040 KB Output is correct
48 Correct 37 ms 80976 KB Output is correct
49 Correct 38 ms 80976 KB Output is correct
50 Correct 35 ms 80980 KB Output is correct
51 Correct 37 ms 80984 KB Output is correct
52 Correct 39 ms 80844 KB Output is correct
53 Correct 36 ms 80976 KB Output is correct
54 Correct 35 ms 80932 KB Output is correct
55 Correct 36 ms 80980 KB Output is correct
56 Correct 38 ms 80832 KB Output is correct
57 Correct 43 ms 80976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 80980 KB Output is correct
2 Correct 47 ms 80980 KB Output is correct
3 Correct 38 ms 80820 KB Output is correct
4 Correct 37 ms 80980 KB Output is correct
5 Correct 37 ms 81060 KB Output is correct
6 Correct 35 ms 80976 KB Output is correct
7 Correct 36 ms 80988 KB Output is correct
8 Correct 36 ms 80984 KB Output is correct
9 Correct 34 ms 80988 KB Output is correct
10 Correct 35 ms 80980 KB Output is correct
11 Correct 34 ms 80988 KB Output is correct
12 Correct 34 ms 80980 KB Output is correct
13 Correct 36 ms 80984 KB Output is correct
14 Correct 36 ms 80988 KB Output is correct
15 Correct 36 ms 80980 KB Output is correct
16 Correct 36 ms 81040 KB Output is correct
17 Correct 38 ms 80976 KB Output is correct
18 Correct 38 ms 80992 KB Output is correct
19 Correct 36 ms 80984 KB Output is correct
20 Correct 36 ms 80980 KB Output is correct
21 Correct 35 ms 80976 KB Output is correct
22 Correct 36 ms 80976 KB Output is correct
23 Correct 35 ms 80980 KB Output is correct
24 Correct 35 ms 80980 KB Output is correct
25 Correct 36 ms 80968 KB Output is correct
26 Correct 36 ms 80976 KB Output is correct
27 Correct 37 ms 80984 KB Output is correct
28 Correct 38 ms 80884 KB Output is correct
29 Correct 35 ms 80980 KB Output is correct
30 Correct 35 ms 80976 KB Output is correct
31 Correct 39 ms 80980 KB Output is correct
32 Correct 35 ms 80976 KB Output is correct
33 Correct 37 ms 80980 KB Output is correct
34 Correct 38 ms 80976 KB Output is correct
35 Correct 37 ms 80980 KB Output is correct
36 Correct 43 ms 80976 KB Output is correct
37 Correct 34 ms 81008 KB Output is correct
38 Correct 37 ms 80976 KB Output is correct
39 Correct 37 ms 80976 KB Output is correct
40 Correct 35 ms 80976 KB Output is correct
41 Correct 39 ms 80980 KB Output is correct
42 Correct 37 ms 80976 KB Output is correct
43 Correct 40 ms 80980 KB Output is correct
44 Correct 36 ms 80928 KB Output is correct
45 Correct 39 ms 80984 KB Output is correct
46 Correct 38 ms 80988 KB Output is correct
47 Correct 39 ms 81040 KB Output is correct
48 Correct 37 ms 80976 KB Output is correct
49 Correct 38 ms 80976 KB Output is correct
50 Correct 35 ms 80980 KB Output is correct
51 Correct 37 ms 80984 KB Output is correct
52 Correct 39 ms 80844 KB Output is correct
53 Correct 36 ms 80976 KB Output is correct
54 Correct 35 ms 80932 KB Output is correct
55 Correct 36 ms 80980 KB Output is correct
56 Correct 38 ms 80832 KB Output is correct
57 Correct 43 ms 80976 KB Output is correct
58 Correct 48 ms 81244 KB Output is correct
59 Correct 42 ms 81640 KB Output is correct
60 Correct 45 ms 81628 KB Output is correct
61 Correct 96 ms 81476 KB Output is correct
62 Correct 194 ms 82404 KB Output is correct
63 Correct 56 ms 82492 KB Output is correct
64 Correct 111 ms 82400 KB Output is correct
65 Correct 35 ms 80980 KB Output is correct
66 Correct 37 ms 80976 KB Output is correct
67 Correct 34 ms 80988 KB Output is correct
68 Correct 36 ms 80840 KB Output is correct
69 Correct 36 ms 81044 KB Output is correct
70 Correct 36 ms 80984 KB Output is correct
71 Correct 56 ms 80980 KB Output is correct
72 Correct 44 ms 80976 KB Output is correct
73 Correct 39 ms 80976 KB Output is correct
74 Correct 39 ms 81500 KB Output is correct
75 Correct 44 ms 81492 KB Output is correct
76 Correct 94 ms 81636 KB Output is correct
77 Correct 211 ms 82516 KB Output is correct
78 Correct 45 ms 82516 KB Output is correct
79 Correct 116 ms 82472 KB Output is correct
80 Correct 46 ms 82288 KB Output is correct
81 Correct 60 ms 82516 KB Output is correct
82 Correct 208 ms 82324 KB Output is correct
83 Correct 38 ms 80976 KB Output is correct
84 Correct 40 ms 81084 KB Output is correct
85 Correct 50 ms 81348 KB Output is correct
86 Correct 42 ms 81192 KB Output is correct
87 Correct 41 ms 81196 KB Output is correct
88 Correct 37 ms 81488 KB Output is correct
89 Correct 44 ms 82244 KB Output is correct
90 Correct 98 ms 82224 KB Output is correct
91 Correct 237 ms 84180 KB Output is correct
92 Correct 53 ms 83880 KB Output is correct
93 Correct 128 ms 84160 KB Output is correct
94 Correct 36 ms 80976 KB Output is correct
95 Correct 51 ms 81220 KB Output is correct
96 Correct 38 ms 80980 KB Output is correct
97 Correct 35 ms 80892 KB Output is correct
98 Correct 37 ms 80844 KB Output is correct
99 Correct 35 ms 80980 KB Output is correct