Submission #960024

# Submission time Handle Problem Language Result Execution time Memory
960024 2024-04-09T13:57:25 Z LCJLY Pinball (JOI14_pinball) C++14
0 / 100
1 ms 452 KB
#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),v(1e15){
		if(s!=e){
			l=new node(s,m);
			r=new node(m+1,e);
		}
	}

	void upd(int x, int y){
		if(s==e){
			v=min(v,y);
			return;
		}
		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;
		}
		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];
	vector<int>v;
	for(int x=0;x<n;x++){
		cin >> arr[x][0] >> arr[x][1] >> arr[x][2] >> arr[x][3];
		v.push_back(arr[x][0]);
		v.push_back(arr[x][1]);
		v.push_back(arr[x][2]);
	}
	
	sort(v.begin(),v.end());
	v.resize(unique(v.begin(),v.end())-v.begin());
	
	for(int x=0;x<n;x++){
		arr[x][0]=lower_bound(v.begin(),v.end(),arr[x][0])-v.begin()+1;
		arr[x][1]=lower_bound(v.begin(),v.end(),arr[x][1])-v.begin()+1;
		arr[x][2]=lower_bound(v.begin(),v.end(),arr[x][2])-v.begin()+1;
	}
	
	int sz=lower_bound(v.begin(),v.end(),m)-v.begin()+1;

	node st(0,sz+5);
	int prefix[n+5];
	st.upd(1,0);
	//show(sz,sz);
	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,sz+5);
	int suffix[n+5];
	st2.upd(sz,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 time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 1 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 1 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 1 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 1 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -