답안 #231000

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
231000 2020-05-12T10:10:10 Z kshitij_sodani Pinball (JOI14_pinball) C++17
100 / 100
285 ms 16400 KB
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define a first
#define b second
#define pb push_back
llo n,m;
llo ac,bc,cd,dd;
llo tree[400001];
llo ma=1000000000000000000;
llo query(llo no,llo l,llo r,llo aa,llo bb){
	if(l>r or l>bb or r<aa){
		return ma;
	}
	if(aa<=l and r<=bb){
		return tree[no];
	}
	else{
		llo mid=(l+r)/2;
		return min(query(no*2+1,l,mid,aa,bb),query(no*2+2,mid+1,r,aa,bb));
	}
}
void update(llo no,llo l,llo r,llo i,llo val){
	if(i<l or i>r){
		return;
	}
	if(l==r and l==i){
		tree[no]=val;
	}
	else{
		llo mid=(l+r)/2;
		update(no*2+1,l,mid,i,val);
		update(no*2+2,mid+1,r,i,val);
		tree[no]=min(tree[no*2+1],tree[no*2+2]);
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
//	memset(tree,ma,sizeof(tree));
	cin>>m>>n;
	for(int i=0;i<4*m+1;i++){
		tree[i]=ma;
	}
	pair<llo,llo> aa[m];
	vector<pair<llo,llo>> bb;
	vector<pair<llo,llo>> cc;

	for(llo i=0;i<m;i++){
		cin>>ac>>bc>>cd>>dd;
		//aa.pb({cd,i});
		aa[i]={cd,i};
		bb.pb({ac,bc});
		cc.pb({cd,dd});
	}
	llo ind[m];
	sort(aa,aa+m);
	for(llo i=0;i<m;i++){
		ind[aa[i].b]=i;
	}
	pair<llo,llo> cost[m];
	pair<llo,llo> cost2[m];
//	cout<<tree[0]<<endl;
	for(llo i=0;i<m;i++){
		if(bb[i].a==1){
			update(0,0,m-1,ind[i],cc[i].b);
			cost[i]={0,cc[i].b};
		}
		else{
		//	cout<<lower_bound(aa,aa+m,mp(bb[i].a,(llo)0))-aa<<" "<<lower_bound(aa,aa+m,mp(bb[i].b+1,(llo)0))-aa-1<<endl;
			llo x=query(0,0,m-1,lower_bound(aa,aa+m,mp(bb[i].a,(llo)0))-aa,lower_bound(aa,aa+m,mp(bb[i].b+1,(llo)0))-aa-1);
			//cout<<x<<endl;
			update(0,0,m-1,ind[i],x+cc[i].b);
			cost[i]={x,cc[i].b};
		}
	}
	for(int i=0;i<4*m+1;i++){
		tree[i]=ma;
	}
	for(llo i=0;i<m;i++){
		if(bb[i].b==n){
			update(0,0,m-1,ind[i],cc[i].b);
			cost2[i]={0,cc[i].b};
		}
		else{
			llo x=query(0,0,m-1,lower_bound(aa,aa+m,mp(bb[i].a,(llo)0))-aa,lower_bound(aa,aa+m,mp(bb[i].b+1,(llo)0))-aa-1);
			update(0,0,m-1,ind[i],x+cc[i].b);
			cost2[i]={x,cc[i].b};
		}
	}
	llo ans=ma;
	llo st=0;
	/*for(llo i=0;i<m;i++){
		cout<<cost[i].a<<","<<cost[i].b<<endl;
	}

	for(llo i=0;i<m;i++){
		cout<<cost2[i].a<<":"<<cost2[i].b<<endl;
	}*/
	for(llo i=0;i<m;i++){
	
		ans=min(ans,(cost[i].a+cost2[i].a+cost[i].b));
	}
	if(ans>=ma){
		cout<<-1<<endl;
		return 0;
	}
	cout<<ans<<endl;













	return 0;
}

Compilation message

pinball.cpp: In function 'int main()':
pinball.cpp:94:6: warning: unused variable 'st' [-Wunused-variable]
  llo st=0;
      ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 432 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 6 ms 572 KB Output is correct
18 Correct 6 ms 512 KB Output is correct
19 Correct 6 ms 512 KB Output is correct
20 Correct 6 ms 512 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 6 ms 512 KB Output is correct
23 Correct 6 ms 512 KB Output is correct
24 Correct 6 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 432 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 6 ms 572 KB Output is correct
18 Correct 6 ms 512 KB Output is correct
19 Correct 6 ms 512 KB Output is correct
20 Correct 6 ms 512 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 6 ms 512 KB Output is correct
23 Correct 6 ms 512 KB Output is correct
24 Correct 6 ms 512 KB Output is correct
25 Correct 25 ms 2044 KB Output is correct
26 Correct 60 ms 4340 KB Output is correct
27 Correct 175 ms 11232 KB Output is correct
28 Correct 261 ms 16088 KB Output is correct
29 Correct 126 ms 8416 KB Output is correct
30 Correct 285 ms 16344 KB Output is correct
31 Correct 271 ms 16336 KB Output is correct
32 Correct 281 ms 16208 KB Output is correct
33 Correct 39 ms 3572 KB Output is correct
34 Correct 125 ms 8420 KB Output is correct
35 Correct 192 ms 16216 KB Output is correct
36 Correct 274 ms 16152 KB Output is correct
37 Correct 231 ms 16220 KB Output is correct
38 Correct 223 ms 16400 KB Output is correct