답안 #960021

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
960021 2024-04-09T13:53:30 Z LCJLY Pinball (JOI14_pinball) C++14
0 / 100
1 ms 604 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),l(NULL),r(NULL),v(1e15){
	}

	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);
	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();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -