답안 #527872

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
527872 2022-02-18T14:43:46 Z Koosha_mv Pinball (JOI14_pinball) C++14
100 / 100
198 ms 52008 KB
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#define int ll

const int N=1e6+99,Max=4e5,inf=1e15;

int m,n,ans=inf,L[N],R[N],seg[2][N];
vector<int> Q[N];

void upd(int x,int val,int s){
	x+=Max;
	while(x) minm(seg[s][x],val),x/=2;
}
int get(int l,int r,int s){
	int res=inf;
	for(l+=Max,r+=Max;l<r;l>>=1,r>>=1){
		if(l&1) minm(res,seg[s][l++]);
		if(r&1) minm(res,seg[s][--r]);
	}
	return res;
}
main(){
	ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
	f(s,0,2) f(i,0,N) seg[s][i]=inf;
	vector<int> vec;
	cin>>m>>n;
	f(i,1,m+1){
		int x;
		f(j,0,3){ cin>>x; Q[i].pb(x); vec.pb(x); }
		cin>>x;
		Q[i].pb(x);
	}
	vec.pb(1);
	vec.pb(n);
	sort(all(vec));
	vec.resize(unique(vec.begin(),vec.end())-vec.begin());
	f(i,1,m+1){
		int l,r,p,cost;
		cost=Q[i][3];
		l=lower_bound(all(vec),Q[i][0])-vec.begin();
		r=lower_bound(all(vec),Q[i][1])-vec.begin();
		p=lower_bound(all(vec),Q[i][2])-vec.begin();
		//cout<<l<<" "<<r<<" "<<p<<endl;
		if(l==0){
			L[i]=0;
		}
		else{
			L[i]=get(l,r+1,0);
		}
		if(r==vec.size()-1){
			R[i]=0;
		}
		else{
			R[i]=get(l,r+1,1);
		}
		L[i]+=cost;
		R[i]+=cost;
		upd(p,L[i],0);
		upd(p,R[i],1);
		minm(ans,L[i]+R[i]-cost);
	}
	cout<<(ans==inf ? -1 : ans);
}

Compilation message

pinball.cpp:41:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   41 | main(){
      | ^~~~
pinball.cpp: In function 'int main()':
pinball.cpp:69:7: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |   if(r==vec.size()-1){
      |      ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 39372 KB Output is correct
2 Correct 18 ms 39464 KB Output is correct
3 Correct 18 ms 39352 KB Output is correct
4 Correct 18 ms 39364 KB Output is correct
5 Correct 19 ms 39500 KB Output is correct
6 Correct 24 ms 39372 KB Output is correct
7 Correct 24 ms 39396 KB Output is correct
8 Correct 19 ms 39460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 39372 KB Output is correct
2 Correct 18 ms 39464 KB Output is correct
3 Correct 18 ms 39352 KB Output is correct
4 Correct 18 ms 39364 KB Output is correct
5 Correct 19 ms 39500 KB Output is correct
6 Correct 24 ms 39372 KB Output is correct
7 Correct 24 ms 39396 KB Output is correct
8 Correct 19 ms 39460 KB Output is correct
9 Correct 18 ms 39412 KB Output is correct
10 Correct 19 ms 39500 KB Output is correct
11 Correct 19 ms 39392 KB Output is correct
12 Correct 18 ms 39500 KB Output is correct
13 Correct 18 ms 39496 KB Output is correct
14 Correct 19 ms 39408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 39372 KB Output is correct
2 Correct 18 ms 39464 KB Output is correct
3 Correct 18 ms 39352 KB Output is correct
4 Correct 18 ms 39364 KB Output is correct
5 Correct 19 ms 39500 KB Output is correct
6 Correct 24 ms 39372 KB Output is correct
7 Correct 24 ms 39396 KB Output is correct
8 Correct 19 ms 39460 KB Output is correct
9 Correct 18 ms 39412 KB Output is correct
10 Correct 19 ms 39500 KB Output is correct
11 Correct 19 ms 39392 KB Output is correct
12 Correct 18 ms 39500 KB Output is correct
13 Correct 18 ms 39496 KB Output is correct
14 Correct 19 ms 39408 KB Output is correct
15 Correct 19 ms 39460 KB Output is correct
16 Correct 19 ms 39500 KB Output is correct
17 Correct 24 ms 39524 KB Output is correct
18 Correct 22 ms 39520 KB Output is correct
19 Correct 23 ms 39624 KB Output is correct
20 Correct 20 ms 39576 KB Output is correct
21 Correct 19 ms 39468 KB Output is correct
22 Correct 19 ms 39468 KB Output is correct
23 Correct 19 ms 39496 KB Output is correct
24 Correct 21 ms 39600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 39372 KB Output is correct
2 Correct 18 ms 39464 KB Output is correct
3 Correct 18 ms 39352 KB Output is correct
4 Correct 18 ms 39364 KB Output is correct
5 Correct 19 ms 39500 KB Output is correct
6 Correct 24 ms 39372 KB Output is correct
7 Correct 24 ms 39396 KB Output is correct
8 Correct 19 ms 39460 KB Output is correct
9 Correct 18 ms 39412 KB Output is correct
10 Correct 19 ms 39500 KB Output is correct
11 Correct 19 ms 39392 KB Output is correct
12 Correct 18 ms 39500 KB Output is correct
13 Correct 18 ms 39496 KB Output is correct
14 Correct 19 ms 39408 KB Output is correct
15 Correct 19 ms 39460 KB Output is correct
16 Correct 19 ms 39500 KB Output is correct
17 Correct 24 ms 39524 KB Output is correct
18 Correct 22 ms 39520 KB Output is correct
19 Correct 23 ms 39624 KB Output is correct
20 Correct 20 ms 39576 KB Output is correct
21 Correct 19 ms 39468 KB Output is correct
22 Correct 19 ms 39468 KB Output is correct
23 Correct 19 ms 39496 KB Output is correct
24 Correct 21 ms 39600 KB Output is correct
25 Correct 30 ms 40600 KB Output is correct
26 Correct 54 ms 42420 KB Output is correct
27 Correct 124 ms 48048 KB Output is correct
28 Correct 124 ms 51768 KB Output is correct
29 Correct 101 ms 45600 KB Output is correct
30 Correct 156 ms 52008 KB Output is correct
31 Correct 187 ms 51948 KB Output is correct
32 Correct 168 ms 51928 KB Output is correct
33 Correct 39 ms 41788 KB Output is correct
34 Correct 94 ms 45576 KB Output is correct
35 Correct 127 ms 51828 KB Output is correct
36 Correct 198 ms 51928 KB Output is correct
37 Correct 160 ms 51880 KB Output is correct
38 Correct 153 ms 51880 KB Output is correct