답안 #870109

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
870109 2023-11-07T01:03:59 Z imarn Pinball (JOI14_pinball) C++14
100 / 100
267 ms 18528 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(){
    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);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 3 ms 10844 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 2 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 3 ms 10844 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 2 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 10692 KB Output is correct
13 Correct 2 ms 10844 KB Output is correct
14 Correct 3 ms 10844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 3 ms 10844 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 2 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 10692 KB Output is correct
13 Correct 2 ms 10844 KB Output is correct
14 Correct 3 ms 10844 KB Output is correct
15 Correct 2 ms 10840 KB Output is correct
16 Correct 2 ms 10840 KB Output is correct
17 Correct 4 ms 10844 KB Output is correct
18 Correct 3 ms 10968 KB Output is correct
19 Correct 3 ms 10844 KB Output is correct
20 Correct 4 ms 10844 KB Output is correct
21 Correct 2 ms 10844 KB Output is correct
22 Correct 3 ms 10948 KB Output is correct
23 Correct 3 ms 10952 KB Output is correct
24 Correct 3 ms 10844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 3 ms 10844 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 2 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 10692 KB Output is correct
13 Correct 2 ms 10844 KB Output is correct
14 Correct 3 ms 10844 KB Output is correct
15 Correct 2 ms 10840 KB Output is correct
16 Correct 2 ms 10840 KB Output is correct
17 Correct 4 ms 10844 KB Output is correct
18 Correct 3 ms 10968 KB Output is correct
19 Correct 3 ms 10844 KB Output is correct
20 Correct 4 ms 10844 KB Output is correct
21 Correct 2 ms 10844 KB Output is correct
22 Correct 3 ms 10948 KB Output is correct
23 Correct 3 ms 10952 KB Output is correct
24 Correct 3 ms 10844 KB Output is correct
25 Correct 18 ms 11580 KB Output is correct
26 Correct 49 ms 12644 KB Output is correct
27 Correct 145 ms 15508 KB Output is correct
28 Correct 198 ms 18372 KB Output is correct
29 Correct 102 ms 14540 KB Output is correct
30 Correct 228 ms 18276 KB Output is correct
31 Correct 215 ms 18376 KB Output is correct
32 Correct 267 ms 18404 KB Output is correct
33 Correct 35 ms 12124 KB Output is correct
34 Correct 96 ms 14644 KB Output is correct
35 Correct 169 ms 18528 KB Output is correct
36 Correct 225 ms 18404 KB Output is correct
37 Correct 186 ms 18372 KB Output is correct
38 Correct 184 ms 18368 KB Output is correct