Submission #959139

# Submission time Handle Problem Language Result Execution time Memory
959139 2024-04-07T14:11:15 Z Blagoj Pinball (JOI14_pinball) C++17
100 / 100
453 ms 44676 KB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define ll long long
#define all(x) (x).begin(), (x).end()

struct SegmentTree {
    vector<ll> sgt;

    SegmentTree(int mxn) {
        sgt.resize(4 * mxn, 1e17);
    }

    void reset() {
        for (int i = 0; i < sgt.size(); i++) sgt[i] = 1e17;
    }

    void update(int k, int l, int r, int i, ll val) {
        if (l > i || r < i) return;
        if (l == r) {
            sgt[k] = min(sgt[k], val);
            return;
        } 
        int mid = (l + r) / 2;
        update(k * 2, l, mid, i, val);
        update(k * 2 + 1, mid + 1, r, i, val);
        sgt[k] = min(sgt[k * 2], sgt[k * 2 + 1]);
    }

    ll get(int k, int l, int r, int i, int j) {
        if (l > j || r < i) return 1e17;
        if (i <= l && r <= j) return sgt[k];
        int mid = (l + r) / 2;
        return min(get(k * 2, l, mid, i, j), get(k * 2 + 1, mid + 1, r, i, j));
    }
} sgt(3e5 + 10);

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    vector<ll> a(n), b(n), c(n), d(n);
    set<ll> points;
    points.insert(1);
    points.insert(m);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        points.insert(a[i]);
        points.insert(b[i]);
        points.insert(c[i]);
    }
    unordered_map<ll, ll> h;
    int cnt = 0;
    for (auto x : points) h[x] = cnt++;
    sgt.update(1, 0, cnt - 1, h[1], 0);
    ll lCost[n], rCost[n];
    for (int i = 0; i < n; i++) {
        lCost[i] = sgt.get(1, 0, cnt - 1, h[a[i]], h[b[i]]);
        sgt.update(1, 0, cnt - 1, h[c[i]], lCost[i] + d[i]);
    }
    sgt.reset();
    sgt.update(1, 0, cnt - 1, h[m], 0);
    for (int i = 0; i < n; i++) {
        rCost[i] = sgt.get(1, 0, cnt - 1, h[a[i]], h[b[i]]);
        sgt.update(1, 0, cnt - 1, h[c[i]], rCost[i] + d[i]);
    }
    ll ans = 1e17;
    for (int i = 0; i < n; i++) ans = min(ans, lCost[i] + d[i] + rCost[i]);
    cout << (ans != 1e17 ? ans : -1);
}

Compilation message

pinball.cpp: In member function 'void SegmentTree::reset()':
pinball.cpp:17:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |         for (int i = 0; i < sgt.size(); i++) sgt[i] = 1e17;
      |                         ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 3 ms 9820 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 2 ms 9820 KB Output is correct
5 Correct 2 ms 9816 KB Output is correct
6 Correct 3 ms 9820 KB Output is correct
7 Correct 3 ms 9820 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 3 ms 9820 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 2 ms 9820 KB Output is correct
5 Correct 2 ms 9816 KB Output is correct
6 Correct 3 ms 9820 KB Output is correct
7 Correct 3 ms 9820 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
9 Correct 3 ms 9820 KB Output is correct
10 Correct 3 ms 9820 KB Output is correct
11 Correct 3 ms 9816 KB Output is correct
12 Correct 3 ms 9820 KB Output is correct
13 Correct 5 ms 9816 KB Output is correct
14 Correct 3 ms 9816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 3 ms 9820 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 2 ms 9820 KB Output is correct
5 Correct 2 ms 9816 KB Output is correct
6 Correct 3 ms 9820 KB Output is correct
7 Correct 3 ms 9820 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
9 Correct 3 ms 9820 KB Output is correct
10 Correct 3 ms 9820 KB Output is correct
11 Correct 3 ms 9816 KB Output is correct
12 Correct 3 ms 9820 KB Output is correct
13 Correct 5 ms 9816 KB Output is correct
14 Correct 3 ms 9816 KB Output is correct
15 Correct 3 ms 9820 KB Output is correct
16 Correct 3 ms 9820 KB Output is correct
17 Correct 5 ms 9820 KB Output is correct
18 Correct 3 ms 9736 KB Output is correct
19 Correct 5 ms 10076 KB Output is correct
20 Correct 4 ms 9820 KB Output is correct
21 Correct 4 ms 9820 KB Output is correct
22 Correct 4 ms 10072 KB Output is correct
23 Correct 4 ms 10076 KB Output is correct
24 Correct 5 ms 10072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 3 ms 9820 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 2 ms 9820 KB Output is correct
5 Correct 2 ms 9816 KB Output is correct
6 Correct 3 ms 9820 KB Output is correct
7 Correct 3 ms 9820 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
9 Correct 3 ms 9820 KB Output is correct
10 Correct 3 ms 9820 KB Output is correct
11 Correct 3 ms 9816 KB Output is correct
12 Correct 3 ms 9820 KB Output is correct
13 Correct 5 ms 9816 KB Output is correct
14 Correct 3 ms 9816 KB Output is correct
15 Correct 3 ms 9820 KB Output is correct
16 Correct 3 ms 9820 KB Output is correct
17 Correct 5 ms 9820 KB Output is correct
18 Correct 3 ms 9736 KB Output is correct
19 Correct 5 ms 10076 KB Output is correct
20 Correct 4 ms 9820 KB Output is correct
21 Correct 4 ms 9820 KB Output is correct
22 Correct 4 ms 10072 KB Output is correct
23 Correct 4 ms 10076 KB Output is correct
24 Correct 5 ms 10072 KB Output is correct
25 Correct 21 ms 11612 KB Output is correct
26 Correct 57 ms 15948 KB Output is correct
27 Correct 160 ms 22372 KB Output is correct
28 Correct 102 ms 14672 KB Output is correct
29 Correct 134 ms 20676 KB Output is correct
30 Correct 155 ms 16212 KB Output is correct
31 Correct 308 ms 28964 KB Output is correct
32 Correct 227 ms 25288 KB Output is correct
33 Correct 38 ms 15980 KB Output is correct
34 Correct 138 ms 25032 KB Output is correct
35 Correct 264 ms 40668 KB Output is correct
36 Correct 453 ms 44676 KB Output is correct
37 Correct 363 ms 44456 KB Output is correct
38 Correct 369 ms 44416 KB Output is correct