Submission #1095295

# Submission time Handle Problem Language Result Execution time Memory
1095295 2024-10-01T19:01:13 Z Saul0906 Pinball (JOI14_pinball) C++14
100 / 100
543 ms 94288 KB
#include <bits/stdc++.h>
#define ll long long
 
using namespace std;
 
ll inf=1e18;
 
struct device{
    ll i, a, b, c, d;
    ll dp[2]={inf, inf};
    bool operator<(const device B)const{
        return b<B.b;
    }
};
 
struct segtree{
    segtree *left, *right;
    int l, r, mid;
    ll mn=inf;
    segtree(int x, int y){
        l=x;
        r=y;
        mid=(l+r)/2;
        if(l==r) return;
        left = new segtree(l,mid);
        right = new segtree(mid+1,r);
    }
    void update(int x, ll dp, bool force=false){
        if(x<l || r<x) return;
        if(x<=l && r<=x){
            mn=min(dp,mn);
            if(force) mn=dp;
            return;
        }
        left->update(x,dp,force);
        right->update(x,dp,force);
        mn=min(left->mn,right->mn);
    }
    ll query(int x, int y){
        if(y<l || r<x) return 1e18;
        if(x<=l && r<=y) return mn;
        return min(left->query(x,y),right->query(x,y));
    }
};
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin>>n>>m;
    vector<device> devs(n);
    ll ans=1e18;
    map<int, int> ccmp;
    set<int> nums;
    for(int i=0; i<n; i++){
        cin>>devs[i].a>>devs[i].b>>devs[i].c>>devs[i].d;
        devs[i].i=i;
        nums.insert(devs[i].a);
        nums.insert(devs[i].b);
        nums.insert(devs[i].c);
    }
    nums.insert(1);
    nums.insert(m);
    int x=0;
    for(auto e:nums) ccmp[e]=x++;
    segtree ST(0,x), ST2(0,x);
    ST.update(0,0);
    for(int i=0; i<n; i++){
        devs[i].a=ccmp[devs[i].a];
        devs[i].b=ccmp[devs[i].b];
        devs[i].c=ccmp[devs[i].c];
    }
    for(int i=0; i<n; i++){
        devs[i].dp[0]=ST.query(devs[i].a,devs[i].b)+devs[i].d;
        ST.update(devs[i].c,devs[i].dp[0]);
    }
    ST2.update(x-1,0);
    for(int i=0; i<n; i++){
        devs[i].dp[1]=ST2.query(devs[i].a,devs[i].b)+devs[i].d;
        ST2.update(devs[i].c,devs[i].dp[1]);
        ans=min(ans,devs[i].dp[1]+devs[i].dp[0]-devs[i].d);
        //cout<<devs[i].a<<" "<<devs[i].b<<" "<<devs[i].c<<" "<<devs[i].dp[0]<<" "<<devs[i].dp[1]<<endl;
    }
    if(ans==inf) cout<<-1<<endl;
    else cout<<ans<<endl;
}
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
5 Correct 0 ms 456 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 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 0 ms 348 KB Output is correct
5 Correct 0 ms 456 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 0 ms 456 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
5 Correct 0 ms 456 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 0 ms 456 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 2 ms 860 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 1116 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 2 ms 1368 KB Output is correct
23 Correct 2 ms 1368 KB Output is correct
24 Correct 2 ms 1372 KB Output is correct
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
5 Correct 0 ms 456 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 0 ms 456 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 2 ms 860 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 1116 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 2 ms 1368 KB Output is correct
23 Correct 2 ms 1368 KB Output is correct
24 Correct 2 ms 1372 KB Output is correct
25 Correct 25 ms 5976 KB Output is correct
26 Correct 91 ms 18260 KB Output is correct
27 Correct 228 ms 35284 KB Output is correct
28 Correct 103 ms 9964 KB Output is correct
29 Correct 171 ms 30800 KB Output is correct
30 Correct 185 ms 14676 KB Output is correct
31 Correct 397 ms 56912 KB Output is correct
32 Correct 352 ms 43604 KB Output is correct
33 Correct 48 ms 18772 KB Output is correct
34 Correct 207 ms 47188 KB Output is correct
35 Correct 289 ms 94032 KB Output is correct
36 Correct 543 ms 94288 KB Output is correct
37 Correct 402 ms 94032 KB Output is correct
38 Correct 376 ms 94032 KB Output is correct