Submission #1098082

# Submission time Handle Problem Language Result Execution time Memory
1098082 2024-10-09T03:30:16 Z anhthi K blocks (IZhO14_blocks) C++14
100 / 100
352 ms 250120 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define ll long long
#define mp(x, y) make_pair(x, y)
#define sz(v) ((int) (v).size())
#define all(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define BIT(x, y) (((x) >> (y)) & 1)
#define pb push_back
#define heap priority_queue
#define max_rng *max_element
#define min_rng *min_element
#define rep(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define forn(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define ford(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)

 
template <class X, class Y>
    inline bool maximize(X &x, Y y) {
        return (x < y ? x = y, true : false);
    }
 
template <class X, class Y>
    inline bool minimize(X &x, Y y) {
        return (x > y ? x = y, true : false);
    }
 
template <class X>
    inline void compress(vector<X> &a) {
        sort(all(a));
        a.resize(unique(all(a)) - a.begin());
    }
 
int ctz(ll x) { return __builtin_ctzll(x); }
int lg(ll x) { return 63 - __builtin_clzll(x); }
int popcount(ll x) { return __builtin_popcount(x); }
 
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) {
    return l + abs((ll) rng()) % (r - l + 1);
}
 
const ll oo = (ll) 1e18 + 5;
const int inf = (ll) 1e9 + 7, mod = (ll) 1e9 + 7;
 
const int N = 3e5 + 5, LOG = 30;
 
void add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
void sub(int &x, int y) { x -= y; if (x < 0) x += mod; }

int n, k;
ll a[N];

ll f[N][105];

int main(void) {
 
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
        
    cin >> n >> k;
    rep(i, n) cin >> a[i];

    memset(f, 0x3f, sizeof (f));    

    f[0][1] = 0;
    forn(i, 1, n) f[i][1] = max(f[i-1][1], a[i]);
    forn(j, 2, k) {
        vector<pair<ll, int>> st;
        forn(i, j, n) {
            ll res = f[i-1][j-1];
            while (sz(st) && a[st.back().second] <= a[i]) {
                minimize(res, st.back().first);
                st.pop_back();
            }
            f[i][j] = min(f[sz(st) ? st.back().second : 0][j], res + a[i]);
            st.pb({res, i});
        } 
    }

    cout << f[n][k];

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 124 ms 246864 KB Output is correct
2 Correct 125 ms 247020 KB Output is correct
3 Correct 122 ms 246884 KB Output is correct
4 Correct 124 ms 246864 KB Output is correct
5 Correct 118 ms 246864 KB Output is correct
6 Correct 128 ms 246860 KB Output is correct
7 Correct 122 ms 246928 KB Output is correct
8 Correct 138 ms 247000 KB Output is correct
9 Correct 125 ms 246800 KB Output is correct
10 Correct 118 ms 246924 KB Output is correct
11 Correct 123 ms 246864 KB Output is correct
12 Correct 121 ms 246868 KB Output is correct
13 Correct 138 ms 246996 KB Output is correct
14 Correct 122 ms 246808 KB Output is correct
15 Correct 140 ms 246840 KB Output is correct
16 Correct 117 ms 246868 KB Output is correct
17 Correct 124 ms 246816 KB Output is correct
18 Correct 121 ms 247000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 246864 KB Output is correct
2 Correct 112 ms 246852 KB Output is correct
3 Correct 107 ms 246868 KB Output is correct
4 Correct 118 ms 246864 KB Output is correct
5 Correct 109 ms 246868 KB Output is correct
6 Correct 110 ms 246864 KB Output is correct
7 Correct 118 ms 246864 KB Output is correct
8 Correct 124 ms 246864 KB Output is correct
9 Correct 118 ms 246868 KB Output is correct
10 Correct 115 ms 246868 KB Output is correct
11 Correct 107 ms 246868 KB Output is correct
12 Correct 115 ms 246912 KB Output is correct
13 Correct 119 ms 246796 KB Output is correct
14 Correct 109 ms 246992 KB Output is correct
15 Correct 104 ms 246928 KB Output is correct
16 Correct 123 ms 246868 KB Output is correct
17 Correct 106 ms 246868 KB Output is correct
18 Correct 126 ms 246780 KB Output is correct
19 Correct 116 ms 246864 KB Output is correct
20 Correct 124 ms 246864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 246864 KB Output is correct
2 Correct 125 ms 247020 KB Output is correct
3 Correct 122 ms 246884 KB Output is correct
4 Correct 124 ms 246864 KB Output is correct
5 Correct 118 ms 246864 KB Output is correct
6 Correct 128 ms 246860 KB Output is correct
7 Correct 122 ms 246928 KB Output is correct
8 Correct 138 ms 247000 KB Output is correct
9 Correct 125 ms 246800 KB Output is correct
10 Correct 118 ms 246924 KB Output is correct
11 Correct 123 ms 246864 KB Output is correct
12 Correct 121 ms 246868 KB Output is correct
13 Correct 138 ms 246996 KB Output is correct
14 Correct 122 ms 246808 KB Output is correct
15 Correct 140 ms 246840 KB Output is correct
16 Correct 117 ms 246868 KB Output is correct
17 Correct 124 ms 246816 KB Output is correct
18 Correct 121 ms 247000 KB Output is correct
19 Correct 109 ms 246864 KB Output is correct
20 Correct 112 ms 246852 KB Output is correct
21 Correct 107 ms 246868 KB Output is correct
22 Correct 118 ms 246864 KB Output is correct
23 Correct 109 ms 246868 KB Output is correct
24 Correct 110 ms 246864 KB Output is correct
25 Correct 118 ms 246864 KB Output is correct
26 Correct 124 ms 246864 KB Output is correct
27 Correct 118 ms 246868 KB Output is correct
28 Correct 115 ms 246868 KB Output is correct
29 Correct 107 ms 246868 KB Output is correct
30 Correct 115 ms 246912 KB Output is correct
31 Correct 119 ms 246796 KB Output is correct
32 Correct 109 ms 246992 KB Output is correct
33 Correct 104 ms 246928 KB Output is correct
34 Correct 123 ms 246868 KB Output is correct
35 Correct 106 ms 246868 KB Output is correct
36 Correct 126 ms 246780 KB Output is correct
37 Correct 116 ms 246864 KB Output is correct
38 Correct 124 ms 246864 KB Output is correct
39 Correct 122 ms 246864 KB Output is correct
40 Correct 119 ms 246840 KB Output is correct
41 Correct 118 ms 246936 KB Output is correct
42 Correct 115 ms 247012 KB Output is correct
43 Correct 104 ms 246980 KB Output is correct
44 Correct 108 ms 246996 KB Output is correct
45 Correct 112 ms 246864 KB Output is correct
46 Correct 107 ms 246868 KB Output is correct
47 Correct 108 ms 246868 KB Output is correct
48 Correct 120 ms 247124 KB Output is correct
49 Correct 118 ms 246876 KB Output is correct
50 Correct 116 ms 246864 KB Output is correct
51 Correct 118 ms 246864 KB Output is correct
52 Correct 121 ms 246864 KB Output is correct
53 Correct 118 ms 246868 KB Output is correct
54 Correct 126 ms 246972 KB Output is correct
55 Correct 121 ms 246900 KB Output is correct
56 Correct 119 ms 246864 KB Output is correct
57 Correct 119 ms 247024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 246864 KB Output is correct
2 Correct 125 ms 247020 KB Output is correct
3 Correct 122 ms 246884 KB Output is correct
4 Correct 124 ms 246864 KB Output is correct
5 Correct 118 ms 246864 KB Output is correct
6 Correct 128 ms 246860 KB Output is correct
7 Correct 122 ms 246928 KB Output is correct
8 Correct 138 ms 247000 KB Output is correct
9 Correct 125 ms 246800 KB Output is correct
10 Correct 118 ms 246924 KB Output is correct
11 Correct 123 ms 246864 KB Output is correct
12 Correct 121 ms 246868 KB Output is correct
13 Correct 138 ms 246996 KB Output is correct
14 Correct 122 ms 246808 KB Output is correct
15 Correct 140 ms 246840 KB Output is correct
16 Correct 117 ms 246868 KB Output is correct
17 Correct 124 ms 246816 KB Output is correct
18 Correct 121 ms 247000 KB Output is correct
19 Correct 109 ms 246864 KB Output is correct
20 Correct 112 ms 246852 KB Output is correct
21 Correct 107 ms 246868 KB Output is correct
22 Correct 118 ms 246864 KB Output is correct
23 Correct 109 ms 246868 KB Output is correct
24 Correct 110 ms 246864 KB Output is correct
25 Correct 118 ms 246864 KB Output is correct
26 Correct 124 ms 246864 KB Output is correct
27 Correct 118 ms 246868 KB Output is correct
28 Correct 115 ms 246868 KB Output is correct
29 Correct 107 ms 246868 KB Output is correct
30 Correct 115 ms 246912 KB Output is correct
31 Correct 119 ms 246796 KB Output is correct
32 Correct 109 ms 246992 KB Output is correct
33 Correct 104 ms 246928 KB Output is correct
34 Correct 123 ms 246868 KB Output is correct
35 Correct 106 ms 246868 KB Output is correct
36 Correct 126 ms 246780 KB Output is correct
37 Correct 116 ms 246864 KB Output is correct
38 Correct 124 ms 246864 KB Output is correct
39 Correct 122 ms 246864 KB Output is correct
40 Correct 119 ms 246840 KB Output is correct
41 Correct 118 ms 246936 KB Output is correct
42 Correct 115 ms 247012 KB Output is correct
43 Correct 104 ms 246980 KB Output is correct
44 Correct 108 ms 246996 KB Output is correct
45 Correct 112 ms 246864 KB Output is correct
46 Correct 107 ms 246868 KB Output is correct
47 Correct 108 ms 246868 KB Output is correct
48 Correct 120 ms 247124 KB Output is correct
49 Correct 118 ms 246876 KB Output is correct
50 Correct 116 ms 246864 KB Output is correct
51 Correct 118 ms 246864 KB Output is correct
52 Correct 121 ms 246864 KB Output is correct
53 Correct 118 ms 246868 KB Output is correct
54 Correct 126 ms 246972 KB Output is correct
55 Correct 121 ms 246900 KB Output is correct
56 Correct 119 ms 246864 KB Output is correct
57 Correct 119 ms 247024 KB Output is correct
58 Correct 132 ms 246964 KB Output is correct
59 Correct 125 ms 247632 KB Output is correct
60 Correct 129 ms 247652 KB Output is correct
61 Correct 174 ms 247444 KB Output is correct
62 Correct 286 ms 248400 KB Output is correct
63 Correct 136 ms 248400 KB Output is correct
64 Correct 195 ms 248300 KB Output is correct
65 Correct 114 ms 246864 KB Output is correct
66 Correct 125 ms 247120 KB Output is correct
67 Correct 122 ms 246912 KB Output is correct
68 Correct 127 ms 246840 KB Output is correct
69 Correct 116 ms 246860 KB Output is correct
70 Correct 124 ms 246976 KB Output is correct
71 Correct 136 ms 247120 KB Output is correct
72 Correct 119 ms 247104 KB Output is correct
73 Correct 129 ms 247120 KB Output is correct
74 Correct 125 ms 247660 KB Output is correct
75 Correct 131 ms 247632 KB Output is correct
76 Correct 174 ms 247632 KB Output is correct
77 Correct 280 ms 248400 KB Output is correct
78 Correct 115 ms 248388 KB Output is correct
79 Correct 188 ms 248400 KB Output is correct
80 Correct 117 ms 248272 KB Output is correct
81 Correct 129 ms 248256 KB Output is correct
82 Correct 281 ms 248248 KB Output is correct
83 Correct 114 ms 246868 KB Output is correct
84 Correct 123 ms 246864 KB Output is correct
85 Correct 148 ms 247060 KB Output is correct
86 Correct 127 ms 247120 KB Output is correct
87 Correct 127 ms 247120 KB Output is correct
88 Correct 129 ms 247468 KB Output is correct
89 Correct 131 ms 248196 KB Output is correct
90 Correct 193 ms 248184 KB Output is correct
91 Correct 352 ms 250120 KB Output is correct
92 Correct 135 ms 250036 KB Output is correct
93 Correct 234 ms 250116 KB Output is correct
94 Correct 128 ms 247120 KB Output is correct
95 Correct 135 ms 246944 KB Output is correct
96 Correct 123 ms 246876 KB Output is correct
97 Correct 122 ms 246864 KB Output is correct
98 Correct 151 ms 246972 KB Output is correct
99 Correct 117 ms 246856 KB Output is correct