답안 #955882

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
955882 2024-03-31T16:03:57 Z VMaksimoski008 Pinball (JOI14_pinball) C++14
100 / 100
357 ms 41428 KB
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
using ll = long long;

const int maxn = 1e5 + 5;

ll dpL[maxn], dpR[maxn];

struct SegTree {
    int n;
    vector<ll> tree;

    SegTree(int _n) : n(_n), tree(4*_n+5, 1e18) {}

    void update(int u, int tl, int tr, int p, ll v) {
        if(tl == tr) {
            tree[u] = min(tree[u], v);
        } else {
            int tm = (tl + tr) / 2;
            if(p <= tm) update(2*u, tl, tm, p, v);
            else update(2*u+1, tm+1, tr, p, v);
            tree[u] = min(tree[2*u], tree[2*u+1]);
        }
    }

    ll query(int u, int tl, int tr, int l, int r) {
        if(tl > tr || l > tr || tl > r) return 1e18;
        if(l <= tl && tr <= r) return tree[u];
        int tm = (tl + tr) / 2;
        return min(
            query(2*u, tl, tm, l, r),
            query(2*u+1, tm+1, tr, l, r)
        );
    }

    void update(int p, ll v) { update(1, 0, n-1, p, v); }
    ll query(int l, int r) { return query(1, 0, n-1, l, r); }
};

int32_t main() {
    int n, m;
    cin >> n >> m;

    vector<array<int, 4> > v(n+2);
    set<int> s; s.insert(1); s.insert(m);

    for(int i=1; i<=n; i++) {
        cin >> v[i][0] >> v[i][1] >> v[i][2] >> v[i][3];
        s.insert(v[i][0]);
        s.insert(v[i][1]);
        s.insert(v[i][2]);
    }

    vector<int> comp(all(s));

    for(int i=1; i<=n; i++) {
        v[i][0] = lower_bound(all(comp), v[i][0]) - comp.begin();
        v[i][1] = lower_bound(all(comp), v[i][1]) - comp.begin();
        v[i][2] = lower_bound(all(comp), v[i][2]) - comp.begin();
    }

    ll ans = 1e18;

    for(int i=1; i<=n; i++) dpL[i] = dpR[i] = 1e18;

    auto check = [&](int i, int j) {
        return v[i][0] <= v[j][2] && v[j][2] <= v[i][1];
    };

    SegTree treeL(comp.size()), treeR(comp.size());

    for(int i=1; i<=n; i++) {
        if(v[i][0] == 0) dpL[i] = v[i][3];
        if(v[i][1] == comp.size()-1) dpR[i] = v[i][3];

        dpL[i] = min(dpL[i], v[i][3] + treeL.query(v[i][0], v[i][1]));
        dpR[i] = min(dpR[i], v[i][3] + treeR.query(v[i][0], v[i][1]));

        ans = min(ans, dpL[i] + dpR[i] - v[i][3]);
        treeL.update(v[i][2], dpL[i]);
        treeR.update(v[i][2], dpR[i]);
    }

    cout << (ans == 1e18 ? -1 : ans) << '\n';
    return 0;
}

Compilation message

pinball.cpp: In function 'int32_t main()':
pinball.cpp:76:20: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         if(v[i][1] == comp.size()-1) dpR[i] = v[i][3];
pinball.cpp:68:10: warning: variable 'check' set but not used [-Wunused-but-set-variable]
   68 |     auto check = [&](int i, int j) {
      |          ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 3 ms 604 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 3 ms 600 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 3 ms 604 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 3 ms 600 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 26 ms 2652 KB Output is correct
26 Correct 67 ms 8276 KB Output is correct
27 Correct 192 ms 16676 KB Output is correct
28 Correct 182 ms 7504 KB Output is correct
29 Correct 144 ms 14164 KB Output is correct
30 Correct 218 ms 9300 KB Output is correct
31 Correct 298 ms 26196 KB Output is correct
32 Correct 279 ms 21080 KB Output is correct
33 Correct 45 ms 8284 KB Output is correct
34 Correct 165 ms 20908 KB Output is correct
35 Correct 246 ms 41132 KB Output is correct
36 Correct 357 ms 41300 KB Output is correct
37 Correct 322 ms 41428 KB Output is correct
38 Correct 317 ms 41296 KB Output is correct