Submission #728349

# Submission time Handle Problem Language Result Execution time Memory
728349 2023-04-22T09:01:54 Z Kahou Pinball (JOI14_pinball) C++14
100 / 100
258 ms 24672 KB
/* In the name of God, aka Allah */
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
#define mk make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll inf = 1e18;
const int N = 3e5 + 50;
int n, m, k, a[N][3], d[N];
pii P[N];
ll seg[2][N<<2];

void build(int c, int u=1, int tl=1, int tr=k) {
        if (tl == tr) {
                seg[c][u] = (tl == 1+c*(k-1)? 0: inf);
                return;
        }
        int md = (tl+tr)>>1;
        int lc = u<<1;
        int rc = u<<1|1;
        build(c, lc, tl, md), build(c, rc, md+1, tr);
        seg[c][u] = min(seg[c][lc], seg[c][rc]);
}
void upd(int c, int id, ll x, int u=1, int tl=1, int tr=k) {
        if (id < tl || tr < id) return;
        if (tl == tr) {
                seg[c][u] = min(seg[c][u], x);
                return;
        }
        int md = (tl+tr)>>1;
        int lc = u<<1;
        int rc = u<<1|1;
        upd(c, id, x, lc, tl, md), upd(c, id, x, rc, md+1, tr);
        seg[c][u] = min(seg[c][lc], seg[c][rc]);
}
ll get(int c, int l, int r, int u=1, int tl=1, int tr=k) {
        if (r < tl || tr < l) return inf;
        if (l <= tl && tr <= r) return seg[c][u];
        int md = (tl+tr)>>1;
        int lc = u<<1;
        int rc = u<<1|1;
        return min(get(c, l, r, lc, tl, md), get(c, l, r, rc, md+1, tr));
}

void solve() {
        cin >> n >> m;
        if (n == 1) return cout << 0 << endl, void();
        for (int i = 1; i <= n; i++) {
                cin >> a[i][0] >> a[i][1] >> a[i][2] >> d[i];
                P[3*i] = {a[i][0], 3*i};
                P[3*i+1] = {a[i][1], 3*i+1};
                P[3*i+2] = {a[i][2], 3*i+2};
        }
        P[1] = {1, 0};
        P[2] = {m, 0};
        sort(P+1, P+3*n+3);
        for (int i = 1; i <= 3*n+2; i++) {
                k += (P[i].F != P[i-1].F);
                if (P[i].S) a[P[i].S/3][P[i].S%3] = k;
        }
        build(0);
        build(1);
        ll ans = inf;
        for (int i = 1; i <= n; i++) {
                ans = min(ans, get(0, a[i][0], a[i][1])+get(1, a[i][0], a[i][1])+d[i]);
                upd(0, a[i][2], get(0, a[i][0], a[i][1])+d[i]);
                upd(1, a[i][2], get(1, a[i][0], a[i][1])+d[i]);
        }
        cout << (ans >= inf? -1 : ans) << endl;
}

int main() {
        ios::sync_with_stdio(0), cin.tie(0);
        solve();
        return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 6 ms 432 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 6 ms 432 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 532 KB Output is correct
25 Correct 18 ms 1784 KB Output is correct
26 Correct 48 ms 3376 KB Output is correct
27 Correct 161 ms 7188 KB Output is correct
28 Correct 153 ms 8012 KB Output is correct
29 Correct 145 ms 8336 KB Output is correct
30 Correct 196 ms 9144 KB Output is correct
31 Correct 258 ms 16352 KB Output is correct
32 Correct 197 ms 12208 KB Output is correct
33 Correct 29 ms 3788 KB Output is correct
34 Correct 118 ms 12436 KB Output is correct
35 Correct 161 ms 24672 KB Output is correct
36 Correct 252 ms 24528 KB Output is correct
37 Correct 205 ms 24576 KB Output is correct
38 Correct 205 ms 24524 KB Output is correct