# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
501904 |
2022-01-04T18:54:09 Z |
Urvuk3 |
Pinball (JOI14_pinball) |
C++17 |
|
234 ms |
524292 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;
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,n,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,n,a[i].a,a[i].b)+a[i].d;
}
update(segL,1,1,n,a[i].c,dpL[i]); update(segR,1,1,n,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
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
78540 KB |
Output is correct |
2 |
Runtime error |
234 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
78540 KB |
Output is correct |
2 |
Runtime error |
234 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
78540 KB |
Output is correct |
2 |
Runtime error |
234 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
78540 KB |
Output is correct |
2 |
Runtime error |
234 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |