# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
492642 |
2021-12-08T09:48:43 Z |
Urvuk3 |
Pinball (JOI14_pinball) |
C++17 |
|
244 ms |
524292 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MAXN=1e5+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(){
PRINT(MAXN);
cin>>n>>m;
a.resize(n+1);
for(int i=1;i<=n;i++) a[i].input();
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==m) 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 |
Runtime error |
244 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
244 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
244 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
244 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |