Submission #870148

# Submission time Handle Problem Language Result Execution time Memory
870148 2023-11-07T05:04:00 Z imarn Pinball (JOI14_pinball) C++14
100 / 100
162 ms 14800 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
using namespace std;
const int N=3e5+5;
ll dr[100001]{0},dl[100001]{0};
struct segment{
    ll t[2*N];
    void build(){
        for(int i=0;i<2*N;i++)t[i]=1e16;
    }
    void upd(int i,ll amt,int sz){
        i+=sz;t[i]=min(t[i],amt);
        for(i>>=1;i;i>>=1){
            t[i]=min(t[2*i],t[2*i+1]);
        }
    }
    ll qr(int l,int r,int sz,ll res=1e16){
        for(l+=sz,r+=sz;l<r;l>>=1,r>>=1){
            if(l&1)res=min(res,t[l++]);
            if(r&1)res=min(res,t[--r]);
        }return res;
    }
}tl,tr;
int main(){
  	ios_base::sync_with_stdio(false);cin.tie(NULL);
    int m,n;cin>>m>>n;tl.build();tr.build();
    int a[m],b[m],c[m],d[m];
    for(int i=0;i<m;i++)cin>>a[i]>>b[i]>>c[i]>>d[i];
    vector<int>co;
    for(int i=0;i<m;i++)co.pb(a[i]),co.pb(b[i]),co.pb(c[i]);
    sort(co.begin(),co.end());
    int M=3*m;ll ans=1e16;
    for(int i=0;i<m;i++){
        dl[i]=dr[i]=1e16;
        ll mnl,mnr;mnl=mnr=1e16;
        if(a[i]==1)dl[i]=d[i],mnl=0;
        if(b[i]==n)dr[i]=d[i],mnr=0;
        a[i]=lower_bound(all(co),a[i])-co.begin();
        b[i]=lower_bound(all(co),b[i])-co.begin();
        c[i]=lower_bound(all(co),c[i])-co.begin();
        ll le=tl.qr(a[i],b[i]+1,M);
        ll re=tr.qr(a[i],b[i]+1,M);
        dl[i]=min(dl[i],le+d[i]);
        dr[i]=min(dr[i],re+d[i]);
        mnl=min(mnl,le);mnr=min(mnr,re);
        tl.upd(c[i],dl[i],M);
        tr.upd(c[i],dr[i],M);
        ans=min(ans,mnl+mnr+d[i]);
    }cout<<(ans==1e16?-1:ans);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 2 ms 10844 KB Output is correct
5 Correct 3 ms 10844 KB Output is correct
6 Correct 2 ms 10844 KB Output is correct
7 Correct 2 ms 10844 KB Output is correct
8 Correct 2 ms 10844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 2 ms 10844 KB Output is correct
5 Correct 3 ms 10844 KB Output is correct
6 Correct 2 ms 10844 KB Output is correct
7 Correct 2 ms 10844 KB Output is correct
8 Correct 2 ms 10844 KB Output is correct
9 Correct 2 ms 10844 KB Output is correct
10 Correct 2 ms 10844 KB Output is correct
11 Correct 2 ms 10844 KB Output is correct
12 Correct 2 ms 10844 KB Output is correct
13 Correct 3 ms 10840 KB Output is correct
14 Correct 2 ms 10840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 2 ms 10844 KB Output is correct
5 Correct 3 ms 10844 KB Output is correct
6 Correct 2 ms 10844 KB Output is correct
7 Correct 2 ms 10844 KB Output is correct
8 Correct 2 ms 10844 KB Output is correct
9 Correct 2 ms 10844 KB Output is correct
10 Correct 2 ms 10844 KB Output is correct
11 Correct 2 ms 10844 KB Output is correct
12 Correct 2 ms 10844 KB Output is correct
13 Correct 3 ms 10840 KB Output is correct
14 Correct 2 ms 10840 KB Output is correct
15 Correct 2 ms 10844 KB Output is correct
16 Correct 2 ms 10844 KB Output is correct
17 Correct 3 ms 10844 KB Output is correct
18 Correct 2 ms 10844 KB Output is correct
19 Correct 3 ms 10844 KB Output is correct
20 Correct 3 ms 10844 KB Output is correct
21 Correct 2 ms 10844 KB Output is correct
22 Correct 3 ms 10844 KB Output is correct
23 Correct 3 ms 10844 KB Output is correct
24 Correct 3 ms 10844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 2 ms 10844 KB Output is correct
5 Correct 3 ms 10844 KB Output is correct
6 Correct 2 ms 10844 KB Output is correct
7 Correct 2 ms 10844 KB Output is correct
8 Correct 2 ms 10844 KB Output is correct
9 Correct 2 ms 10844 KB Output is correct
10 Correct 2 ms 10844 KB Output is correct
11 Correct 2 ms 10844 KB Output is correct
12 Correct 2 ms 10844 KB Output is correct
13 Correct 3 ms 10840 KB Output is correct
14 Correct 2 ms 10840 KB Output is correct
15 Correct 2 ms 10844 KB Output is correct
16 Correct 2 ms 10844 KB Output is correct
17 Correct 3 ms 10844 KB Output is correct
18 Correct 2 ms 10844 KB Output is correct
19 Correct 3 ms 10844 KB Output is correct
20 Correct 3 ms 10844 KB Output is correct
21 Correct 2 ms 10844 KB Output is correct
22 Correct 3 ms 10844 KB Output is correct
23 Correct 3 ms 10844 KB Output is correct
24 Correct 3 ms 10844 KB Output is correct
25 Correct 13 ms 11096 KB Output is correct
26 Correct 29 ms 11744 KB Output is correct
27 Correct 84 ms 13216 KB Output is correct
28 Correct 123 ms 14628 KB Output is correct
29 Correct 59 ms 12764 KB Output is correct
30 Correct 122 ms 14552 KB Output is correct
31 Correct 153 ms 14540 KB Output is correct
32 Correct 162 ms 14548 KB Output is correct
33 Correct 22 ms 11468 KB Output is correct
34 Correct 65 ms 12764 KB Output is correct
35 Correct 74 ms 14540 KB Output is correct
36 Correct 130 ms 14544 KB Output is correct
37 Correct 109 ms 14800 KB Output is correct
38 Correct 103 ms 14544 KB Output is correct