Submission #960020

#TimeUsernameProblemLanguageResultExecution timeMemory
960020LCJLYPinball (JOI14_pinball)C++14
51 / 100
862 ms524288 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define show(x,y) cout << y << " " << #x << endl; #define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl; #define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl; #define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl; typedef pair<long long,int>pii; //typedef pair<pii,pii>pi2; typedef array<int,3>pi2; mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); inline int combine(int a, int b){ return min(a,b); } struct node{ int s,e,m; node *l,*r; int v; node(int ss, int ee):s(ss),e(ee),m((s+e)>>1),l(NULL),r(NULL),v(1e15){ } inline void inst(){ if(l==NULL) l=new node(s,m); if(r==NULL) r=new node(m+1,e); } void upd(int x, int y){ if(s==e){ v=min(v,y); return; } inst(); if(x<=m) l->upd(x,y); else r->upd(x,y); v=combine(l->v,r->v); } int query(int x, int y){ if(x<=s&&y>=e){ return v; } inst(); if(y<=m) return l->query(x,y); if(x>m) return r->query(x,y); return combine(l->query(x,m),r->query(m+1,y)); } }; void solve(){ int n,m; cin >> n >> m; array<int,4>arr[n]; for(int x=0;x<n;x++){ cin >> arr[x][0] >> arr[x][1] >> arr[x][2] >> arr[x][3]; } node st(0,m+5); int prefix[n+5]; st.upd(1,0); for(int x=0;x<n;x++){ prefix[x]=1e15; int hold=st.query(arr[x][0],arr[x][1])+arr[x][3]; st.upd(arr[x][2],hold); prefix[x]=hold; } node st2(0,m+5); int suffix[n+5]; st2.upd(m,0); for(int x=0;x<n;x++){ suffix[x]=1e15; int hold=st2.query(arr[x][0],arr[x][1])+arr[x][3]; st2.upd(arr[x][2],hold); suffix[x]=hold; } int best=1e16; for(int x=0;x<n;x++){ //show2(prefix[x],prefix[x],suffix[x],suffix[x]); best=min(best,prefix[x]+suffix[x]-arr[x][3]); } if(best>=1e15) cout << -1; else cout << best; } int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); int t=1; //cin >> t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...