Submission #959133

# Submission time Handle Problem Language Result Execution time Memory
959133 2024-04-07T14:08:06 Z Blagoj Pinball (JOI14_pinball) C++17
51 / 100
319 ms 81188 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(3 * mxn, 1e16);
    }

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

    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 1e16;
        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 = 1e16;
    for (int i = 0; i < n; i++) ans = min(ans, lCost[i] + d[i] + rCost[i]);
    cout << (ans != 1e16 ? 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] = 1e16;
      |                         ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7260 KB Output is correct
2 Correct 3 ms 7260 KB Output is correct
3 Correct 2 ms 7516 KB Output is correct
4 Correct 3 ms 7260 KB Output is correct
5 Correct 3 ms 7512 KB Output is correct
6 Correct 3 ms 7256 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 3 ms 7260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7260 KB Output is correct
2 Correct 3 ms 7260 KB Output is correct
3 Correct 2 ms 7516 KB Output is correct
4 Correct 3 ms 7260 KB Output is correct
5 Correct 3 ms 7512 KB Output is correct
6 Correct 3 ms 7256 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 3 ms 7260 KB Output is correct
9 Correct 2 ms 7516 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 3 ms 7516 KB Output is correct
12 Correct 3 ms 7588 KB Output is correct
13 Correct 3 ms 7512 KB Output is correct
14 Correct 3 ms 7516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7260 KB Output is correct
2 Correct 3 ms 7260 KB Output is correct
3 Correct 2 ms 7516 KB Output is correct
4 Correct 3 ms 7260 KB Output is correct
5 Correct 3 ms 7512 KB Output is correct
6 Correct 3 ms 7256 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 3 ms 7260 KB Output is correct
9 Correct 2 ms 7516 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 3 ms 7516 KB Output is correct
12 Correct 3 ms 7588 KB Output is correct
13 Correct 3 ms 7512 KB Output is correct
14 Correct 3 ms 7516 KB Output is correct
15 Correct 3 ms 7516 KB Output is correct
16 Correct 3 ms 7516 KB Output is correct
17 Correct 4 ms 7516 KB Output is correct
18 Correct 4 ms 7476 KB Output is correct
19 Correct 6 ms 7772 KB Output is correct
20 Correct 3 ms 7512 KB Output is correct
21 Correct 3 ms 7516 KB Output is correct
22 Correct 4 ms 7768 KB Output is correct
23 Correct 5 ms 7768 KB Output is correct
24 Correct 5 ms 7788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7260 KB Output is correct
2 Correct 3 ms 7260 KB Output is correct
3 Correct 2 ms 7516 KB Output is correct
4 Correct 3 ms 7260 KB Output is correct
5 Correct 3 ms 7512 KB Output is correct
6 Correct 3 ms 7256 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 3 ms 7260 KB Output is correct
9 Correct 2 ms 7516 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 3 ms 7516 KB Output is correct
12 Correct 3 ms 7588 KB Output is correct
13 Correct 3 ms 7512 KB Output is correct
14 Correct 3 ms 7516 KB Output is correct
15 Correct 3 ms 7516 KB Output is correct
16 Correct 3 ms 7516 KB Output is correct
17 Correct 4 ms 7516 KB Output is correct
18 Correct 4 ms 7476 KB Output is correct
19 Correct 6 ms 7772 KB Output is correct
20 Correct 3 ms 7512 KB Output is correct
21 Correct 3 ms 7516 KB Output is correct
22 Correct 4 ms 7768 KB Output is correct
23 Correct 5 ms 7768 KB Output is correct
24 Correct 5 ms 7788 KB Output is correct
25 Correct 25 ms 9560 KB Output is correct
26 Correct 69 ms 14432 KB Output is correct
27 Correct 155 ms 22380 KB Output is correct
28 Correct 100 ms 16124 KB Output is correct
29 Correct 113 ms 20076 KB Output is correct
30 Correct 148 ms 17488 KB Output is correct
31 Correct 319 ms 30664 KB Output is correct
32 Correct 247 ms 26820 KB Output is correct
33 Correct 38 ms 14184 KB Output is correct
34 Correct 130 ms 24776 KB Output is correct
35 Runtime error 166 ms 81188 KB Execution killed with signal 11
36 Halted 0 ms 0 KB -