답안 #501909

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
501909 2022-01-04T19:08:06 Z Urvuk3 Pinball (JOI14_pinball) C++17
29 / 100
41 ms 78636 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
const ll MAXN=1e6+5,MAXA=5e6+5,INF=1e9,LINF=1e18;
#define fi first
#define se second
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mid (l+r)/2
#define sz(a) int((a).size())
#define all(a) a.begin(),a.end()
#define mod 1000000007LL
#define pb push_back
#define endl "\n"
#define PRINT(x) cerr<<#x<<'-'<<x<<endl<<flush;
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define pb push_back
#define pf push_front
#define ppf pop_front
#define ppb pop_back
#define PRINTvec(x) { cerr<<#x<<"-"; for(int i=0;i<sz(x);i++) cerr<<x[i]<<" "; cerr<<endl; }

ll n,m,k,q,x,y,z,res=LINF,l,r;
string s,t;
ifstream input;
ofstream output;

#ifdef ONLINE_JUDGE
    #define input cin
    #define output cout
#endif

vector<ll> segL(4*MAXN,LINF),segR(4*MAXN,LINF);
vector<ll> dpL(MAXN),dpR(MAXN);

void update(vector<ll>& seg,int node,int l,int r,int idx,ll val){
    if(l==r){
        seg[node]=min(seg[node],val);
        return;
    }
    if(idx<=mid) update(seg,2*node,l,mid,idx,val);
    else update(seg,2*node+1,mid+1,r,idx,val);
    seg[node]=min(seg[2*node],seg[2*node+1]);
}

ll query(vector<ll>& seg,int node,int l,int r,int L,int R){
    if(L<=l && r<=R){
        return seg[node];
    }
    ll ret=LINF;
    if(L<=mid) ret=min(ret,query(seg,2*node,l,mid,L,R));
    if(R>mid) ret=min(ret,query(seg,2*node+1,mid+1,r,L,R));
    return ret;
}

struct dev{
    int a,b,c,d;
    void input(){
        cin>>a>>b>>c>>d;
    }
    void output(){
        cout<<"a="<<a<<" b="<<b<<" c="<<c<<" d="<<d<<endl;
    }
};

vector<dev> a;

void solve(){
    cin>>n>>m;
    a.resize(n+1);
    vector<int> svi;
    svi.pb(1); svi.pb(n);
    for(int i=1;i<=n;i++){
        a[i].input();
        svi.pb(a[i].a); svi.pb(a[i].b); svi.pb(a[i].c);
    }
    getunique(svi);
    map<int,int> val;
    for(int i=0;i<sz(svi);i++){
        val[svi[i]]=i+1;
    }
    for(int i=1;i<=n;i++){
        a[i].a=val[a[i].a];
        a[i].b=val[a[i].b];
        a[i].c=val[a[i].c];
    }
    for(int i=1;i<=n;i++){
        if(a[i].a==1){
            dpL[i]=a[i].d;
        }
        else{
            dpL[i]=query(segL,1,1,sz(svi),a[i].a,a[i].b)+a[i].d;
        }
        if(a[i].b==sz(svi)){
            dpR[i]=a[i].d;
        }
        else{
            dpR[i]=query(segR,1,1,sz(svi),a[i].a,a[i].b)+a[i].d;
        }
        update(segL,1,1,sz(svi),a[i].c,dpL[i]);
        update(segR,1,1,sz(svi),a[i].c,dpR[i]);
    }
    for(int i=1;i<=n;i++){
        ///cout<<"dpL["<<i<<"]="<<dpL[i]<<endl;
        ///cout<<"dpR["<<i<<"]="<<dpR[i]<<endl;
        if(dpL[i]>=LINF || dpR[i]>=LINF) continue;
        res=min(res,dpL[i]+dpR[i]-a[i].d);
    }
    cout<<(res!=LINF ? res : -1)<<endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        input.open("D:\\UROS\\Programiranje\\input.in",ios::in);
	output.open("D:\\UROS\\Programiranje\\output.out",ios::out|ios::trunc);
    #endif
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    int t;
    //cin>>t;
    t=1;
    while(t--){
        solve();
    }
    return 0;
}

/*
5 6
2 4 3 5
1 2 2 8
3 6 5 2
4 6 4 7
2 4 3 10
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 78536 KB Output is correct
2 Correct 36 ms 78596 KB Output is correct
3 Correct 30 ms 78592 KB Output is correct
4 Correct 35 ms 78504 KB Output is correct
5 Correct 40 ms 78568 KB Output is correct
6 Correct 41 ms 78576 KB Output is correct
7 Correct 29 ms 78540 KB Output is correct
8 Correct 31 ms 78604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 78536 KB Output is correct
2 Correct 36 ms 78596 KB Output is correct
3 Correct 30 ms 78592 KB Output is correct
4 Correct 35 ms 78504 KB Output is correct
5 Correct 40 ms 78568 KB Output is correct
6 Correct 41 ms 78576 KB Output is correct
7 Correct 29 ms 78540 KB Output is correct
8 Correct 31 ms 78604 KB Output is correct
9 Correct 29 ms 78544 KB Output is correct
10 Correct 32 ms 78620 KB Output is correct
11 Correct 30 ms 78560 KB Output is correct
12 Correct 30 ms 78520 KB Output is correct
13 Correct 38 ms 78560 KB Output is correct
14 Correct 32 ms 78636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 78536 KB Output is correct
2 Correct 36 ms 78596 KB Output is correct
3 Correct 30 ms 78592 KB Output is correct
4 Correct 35 ms 78504 KB Output is correct
5 Correct 40 ms 78568 KB Output is correct
6 Correct 41 ms 78576 KB Output is correct
7 Correct 29 ms 78540 KB Output is correct
8 Correct 31 ms 78604 KB Output is correct
9 Correct 29 ms 78544 KB Output is correct
10 Correct 32 ms 78620 KB Output is correct
11 Correct 30 ms 78560 KB Output is correct
12 Correct 30 ms 78520 KB Output is correct
13 Correct 38 ms 78560 KB Output is correct
14 Correct 32 ms 78636 KB Output is correct
15 Correct 33 ms 78608 KB Output is correct
16 Incorrect 38 ms 78588 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 78536 KB Output is correct
2 Correct 36 ms 78596 KB Output is correct
3 Correct 30 ms 78592 KB Output is correct
4 Correct 35 ms 78504 KB Output is correct
5 Correct 40 ms 78568 KB Output is correct
6 Correct 41 ms 78576 KB Output is correct
7 Correct 29 ms 78540 KB Output is correct
8 Correct 31 ms 78604 KB Output is correct
9 Correct 29 ms 78544 KB Output is correct
10 Correct 32 ms 78620 KB Output is correct
11 Correct 30 ms 78560 KB Output is correct
12 Correct 30 ms 78520 KB Output is correct
13 Correct 38 ms 78560 KB Output is correct
14 Correct 32 ms 78636 KB Output is correct
15 Correct 33 ms 78608 KB Output is correct
16 Incorrect 38 ms 78588 KB Output isn't correct
17 Halted 0 ms 0 KB -