Submission #1086046

# Submission time Handle Problem Language Result Execution time Memory
1086046 2024-09-09T11:31:41 Z Icelast Pinball (JOI14_pinball) C++17
100 / 100
198 ms 30944 KB
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 2*1e5+5, INF = 4e18+9;
struct device{
    ll l, r, m, c, id;
};
struct normalize{
    vector<ll> poi, pot;
    void add(ll x){
        poi.push_back(x);
    }
    void start(){
        sort(poi.begin(), poi.end());
        pot.push_back(poi[0]);
        for(int i = 1; i < (int)poi.size(); i++){
            if(poi[i] != poi[i-1]){
                pot.push_back(poi[i]);
            }
        }
    }
    int encode(ll x){
        return lower_bound(pot.begin(), pot.end(), x) - pot.begin()+1;
    }
};
struct SegmentTree{
    struct Node{
        ll mn = INF;
    };
    vector<Node> T;
    int n, N;
    SegmentTree(int n) : n(n){
        N = 1;
        while(N < n) N*=2;
        T.resize(N*2+1);
    };
    void upd(int i, ll x){
        auto upd = [&](auto upd, int node, int low, int high, int i, ll x) -> void{
            if(low == high){
                T[node].mn = min(T[node].mn, x);
                return;
            }
            int mid = (low+high)/2;
            if(i <= mid){
                upd(upd, node*2, low, mid, i, x);
            }else{
                upd(upd, node*2+1, mid+1, high, i, x);
            }
            T[node].mn = min(T[node*2].mn, T[node*2+1].mn);
        };
        upd(upd, 1, 1, N, i, x);
    }
    ll get_min(int l, int r){
        auto get_min = [&](auto get_min, int node, int low, int high, int l, int r) -> ll{
            if(low > r || l > high) return INF;
            if(low >= l && r >= high) return T[node].mn;
            int mid = (low+high)/2;
            return min(get_min(get_min, node*2, low, mid, l, r), get_min(get_min, node*2+1, mid+1, high, l, r));
        };
        return get_min(get_min, 1, 1, N, l, r);
    }
};
void solve(){
    int n, m;
    cin >> n >> m;
    vector<device> a(n+1);
    for(int i = 1; i <= n; i++){
        cin >> a[i].l >> a[i].r >> a[i].m >> a[i].c;
        a[i].id = i;
    }
    normalize norm;
    norm.add(1);
    norm.add(m);
    for(int i = 1; i <= n; i++){
        norm.add(a[i].l);
        norm.add(a[i].r);
        norm.add(a[i].m);
    }
    norm.start();
    m = norm.encode(m);
    for(int i = 1; i <= n; i++){
        a[i].l = norm.encode(a[i].l);
        a[i].r = norm.encode(a[i].r);
        a[i].m = norm.encode(a[i].m);
    }

    int N = 3*n+2;
    SegmentTree Tl(N+1), Tr(N+1);
    Tl.upd(1, 0);
    Tr.upd(m, 0);
    vector<ll> dpl(n+1, INF), dpr(n+1, INF);
    for(int i = 1; i <= n; i++){
        dpl[i] = Tl.get_min(a[i].l, a[i].r)+a[i].c;
        Tl.upd(a[i].m, dpl[i]);
        dpr[i] = Tr.get_min(a[i].l, a[i].r)+a[i].c;
        Tr.upd(a[i].m, dpr[i]);
    }
    ll ans = INF;
    for(int i = 1; i <= n; i++){
        ans = min(ans, dpl[i]+dpr[i]-a[i].c);
    }
    if(ans == INF) ans = -1;
    cout << ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 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
# Verdict Execution time Memory Grader output
1 Correct 1 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 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 2 ms 536 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 2 ms 536 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 13 ms 2680 KB Output is correct
26 Correct 42 ms 7888 KB Output is correct
27 Correct 124 ms 17868 KB Output is correct
28 Correct 113 ms 28412 KB Output is correct
29 Correct 100 ms 15444 KB Output is correct
30 Correct 160 ms 28868 KB Output is correct
31 Correct 179 ms 30148 KB Output is correct
32 Correct 170 ms 29696 KB Output is correct
33 Correct 21 ms 5216 KB Output is correct
34 Correct 78 ms 15440 KB Output is correct
35 Correct 116 ms 30780 KB Output is correct
36 Correct 198 ms 30780 KB Output is correct
37 Correct 162 ms 30944 KB Output is correct
38 Correct 156 ms 30692 KB Output is correct