Submission #1101454

# Submission time Handle Problem Language Result Execution time Memory
1101454 2024-10-16T08:40:18 Z Anphat K blocks (IZhO14_blocks) C++14
53 / 100
723 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f first
#define s second
#define sz(a) (int)(a.size())
#define all(a) a.begin(), a.end()
#define uni(a) sort(all(a)), a.resize(unique(all(a)) - a.begin())

typedef pair <int, int> ii;

const int N = 1e5 + 5;

int n, k, a[N], ans, l[N], r[N];
stack <int> st;

struct segtree {
    int seg[N << 2], lazy[N << 2];

    void reset() {
        for (int i = 1; i <= (n << 2); i++) lazy[i] = seg[i] = 1e9;
    }

    void apply(int id, int val) {
        seg[id] = min(seg[id], val);
        lazy[id] = min(lazy[id], val);
    }

    void push(int id) {
        if (lazy[id] == 1e9) return;
        apply(id << 1, lazy[id]);
        apply(id << 1 | 1, lazy[id]);
        lazy[id] = 1e9;
    }

    void up(int l, int r, int id, int u, int v, int val) {
        if (l > v || r < u) return;
        if (l >= u && r <= v) {
            apply(id, val);
            return;
        }
        push(id);
        int mid = (l + r) >> 1;
        up(l, mid, id << 1, u, v, val);
        up(mid + 1, r, id << 1 | 1, u, v, val);
        seg[id] = min(seg[id << 1], seg[id << 1 | 1]);
    }

    void up(int l, int r, int val) {
        up(0, n, 1, l, r, val);
    }

    int get(int l, int r, int id, int u, int v) {
        if (l > v || r < u) return 1e9;
        if (l >= u && r <= v) return seg[id];
        push(id);
        int mid = (l + r) >> 1;
        return min(get(l, mid, id << 1, u, v), get(mid + 1, r, id << 1 | 1, u, v));
    }

    int get(int l, int r) {
        return get(0, n, 1, l, r);
    }
} seg[101];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    //freopen("a.inp", "r", stdin);
    //freopen("a.out", "w", stdout);

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

    a[0] = a[n + 1] = 1e9;
    st.push(0);

    for (int i = 1; i <= n; i++) {
        while (a[st.top()] <= a[i]) st.pop();
        l[i] = st.top();
        st.push(i);
    }

    while (sz(st)) st.pop();
    st.push(n + 1);

    for (int i = n; i >= 1; i--) {
        while (a[st.top()] <= a[i]) st.pop();
        r[i] = st.top();
        st.push(i);
    }

    for (int i = 0; i <= k; i++) {
        seg[i].reset();
    }

    seg[0].reset(); seg[0].up(0, 0, 0);

    for (int j = 1; j <= k; j++) {
        for (int i = 1; i <= n; i++) {
            seg[j].up(i, r[i] - 1, seg[(j - 1)].get(l[i], i - 1) + a[i]);
        }
    }

    cout << seg[k].get(n, n) << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 2 ms 8700 KB Output is correct
5 Correct 2 ms 8528 KB Output is correct
6 Correct 1 ms 6532 KB Output is correct
7 Correct 2 ms 8528 KB Output is correct
8 Correct 1 ms 8700 KB Output is correct
9 Correct 2 ms 12624 KB Output is correct
10 Correct 2 ms 14672 KB Output is correct
11 Correct 2 ms 18768 KB Output is correct
12 Correct 1 ms 6480 KB Output is correct
13 Correct 2 ms 18768 KB Output is correct
14 Correct 2 ms 18768 KB Output is correct
15 Correct 2 ms 6480 KB Output is correct
16 Correct 2 ms 12796 KB Output is correct
17 Correct 1 ms 6480 KB Output is correct
18 Correct 3 ms 18768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 1 ms 8528 KB Output is correct
5 Correct 2 ms 8528 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 2 ms 8696 KB Output is correct
8 Correct 1 ms 8528 KB Output is correct
9 Correct 2 ms 12624 KB Output is correct
10 Correct 2 ms 14672 KB Output is correct
11 Correct 2 ms 18940 KB Output is correct
12 Correct 2 ms 20816 KB Output is correct
13 Correct 3 ms 24912 KB Output is correct
14 Correct 4 ms 33116 KB Output is correct
15 Correct 4 ms 33104 KB Output is correct
16 Correct 5 ms 49488 KB Output is correct
17 Correct 5 ms 49488 KB Output is correct
18 Correct 4 ms 33104 KB Output is correct
19 Correct 6 ms 49488 KB Output is correct
20 Correct 6 ms 62032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 2 ms 8700 KB Output is correct
5 Correct 2 ms 8528 KB Output is correct
6 Correct 1 ms 6532 KB Output is correct
7 Correct 2 ms 8528 KB Output is correct
8 Correct 1 ms 8700 KB Output is correct
9 Correct 2 ms 12624 KB Output is correct
10 Correct 2 ms 14672 KB Output is correct
11 Correct 2 ms 18768 KB Output is correct
12 Correct 1 ms 6480 KB Output is correct
13 Correct 2 ms 18768 KB Output is correct
14 Correct 2 ms 18768 KB Output is correct
15 Correct 2 ms 6480 KB Output is correct
16 Correct 2 ms 12796 KB Output is correct
17 Correct 1 ms 6480 KB Output is correct
18 Correct 3 ms 18768 KB Output is correct
19 Correct 1 ms 6480 KB Output is correct
20 Correct 1 ms 6480 KB Output is correct
21 Correct 1 ms 6480 KB Output is correct
22 Correct 1 ms 8528 KB Output is correct
23 Correct 2 ms 8528 KB Output is correct
24 Correct 1 ms 6480 KB Output is correct
25 Correct 2 ms 8696 KB Output is correct
26 Correct 1 ms 8528 KB Output is correct
27 Correct 2 ms 12624 KB Output is correct
28 Correct 2 ms 14672 KB Output is correct
29 Correct 2 ms 18940 KB Output is correct
30 Correct 2 ms 20816 KB Output is correct
31 Correct 3 ms 24912 KB Output is correct
32 Correct 4 ms 33116 KB Output is correct
33 Correct 4 ms 33104 KB Output is correct
34 Correct 5 ms 49488 KB Output is correct
35 Correct 5 ms 49488 KB Output is correct
36 Correct 4 ms 33104 KB Output is correct
37 Correct 6 ms 49488 KB Output is correct
38 Correct 6 ms 62032 KB Output is correct
39 Correct 15 ms 158288 KB Output is correct
40 Correct 1 ms 6480 KB Output is correct
41 Correct 1 ms 6480 KB Output is correct
42 Correct 1 ms 6480 KB Output is correct
43 Correct 1 ms 8528 KB Output is correct
44 Correct 1 ms 8528 KB Output is correct
45 Correct 1 ms 6480 KB Output is correct
46 Correct 1 ms 8528 KB Output is correct
47 Correct 1 ms 8528 KB Output is correct
48 Correct 2 ms 12624 KB Output is correct
49 Correct 2 ms 14672 KB Output is correct
50 Correct 3 ms 18768 KB Output is correct
51 Correct 8 ms 80632 KB Output is correct
52 Correct 8 ms 80464 KB Output is correct
53 Correct 25 ms 261388 KB Output is correct
54 Correct 24 ms 261200 KB Output is correct
55 Correct 17 ms 168608 KB Output is correct
56 Correct 25 ms 261192 KB Output is correct
57 Correct 25 ms 261192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 2 ms 8700 KB Output is correct
5 Correct 2 ms 8528 KB Output is correct
6 Correct 1 ms 6532 KB Output is correct
7 Correct 2 ms 8528 KB Output is correct
8 Correct 1 ms 8700 KB Output is correct
9 Correct 2 ms 12624 KB Output is correct
10 Correct 2 ms 14672 KB Output is correct
11 Correct 2 ms 18768 KB Output is correct
12 Correct 1 ms 6480 KB Output is correct
13 Correct 2 ms 18768 KB Output is correct
14 Correct 2 ms 18768 KB Output is correct
15 Correct 2 ms 6480 KB Output is correct
16 Correct 2 ms 12796 KB Output is correct
17 Correct 1 ms 6480 KB Output is correct
18 Correct 3 ms 18768 KB Output is correct
19 Correct 1 ms 6480 KB Output is correct
20 Correct 1 ms 6480 KB Output is correct
21 Correct 1 ms 6480 KB Output is correct
22 Correct 1 ms 8528 KB Output is correct
23 Correct 2 ms 8528 KB Output is correct
24 Correct 1 ms 6480 KB Output is correct
25 Correct 2 ms 8696 KB Output is correct
26 Correct 1 ms 8528 KB Output is correct
27 Correct 2 ms 12624 KB Output is correct
28 Correct 2 ms 14672 KB Output is correct
29 Correct 2 ms 18940 KB Output is correct
30 Correct 2 ms 20816 KB Output is correct
31 Correct 3 ms 24912 KB Output is correct
32 Correct 4 ms 33116 KB Output is correct
33 Correct 4 ms 33104 KB Output is correct
34 Correct 5 ms 49488 KB Output is correct
35 Correct 5 ms 49488 KB Output is correct
36 Correct 4 ms 33104 KB Output is correct
37 Correct 6 ms 49488 KB Output is correct
38 Correct 6 ms 62032 KB Output is correct
39 Correct 15 ms 158288 KB Output is correct
40 Correct 1 ms 6480 KB Output is correct
41 Correct 1 ms 6480 KB Output is correct
42 Correct 1 ms 6480 KB Output is correct
43 Correct 1 ms 8528 KB Output is correct
44 Correct 1 ms 8528 KB Output is correct
45 Correct 1 ms 6480 KB Output is correct
46 Correct 1 ms 8528 KB Output is correct
47 Correct 1 ms 8528 KB Output is correct
48 Correct 2 ms 12624 KB Output is correct
49 Correct 2 ms 14672 KB Output is correct
50 Correct 3 ms 18768 KB Output is correct
51 Correct 8 ms 80632 KB Output is correct
52 Correct 8 ms 80464 KB Output is correct
53 Correct 25 ms 261388 KB Output is correct
54 Correct 24 ms 261200 KB Output is correct
55 Correct 17 ms 168608 KB Output is correct
56 Correct 25 ms 261192 KB Output is correct
57 Correct 25 ms 261192 KB Output is correct
58 Correct 52 ms 80720 KB Output is correct
59 Correct 15 ms 7416 KB Output is correct
60 Correct 77 ms 25680 KB Output is correct
61 Correct 723 ms 241300 KB Output is correct
62 Runtime error 67 ms 262144 KB Execution killed with signal 9
63 Halted 0 ms 0 KB -