답안 #239795

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
239795 2020-06-17T10:01:12 Z Knps4422 Pinball (JOI14_pinball) C++14
0 / 100
8 ms 6656 KB
//#pragma optimization_level 3
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordset;
*/
 
#define fr first
#define sc second
#define vec vector
#define pb push_back
#define pii pair<int, int>
#define forn(x,y) for(ll x = 1 ; x <= y ; ++x)
#define all(x) (x).begin(),(x).end()
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);

 
using namespace std;
 
typedef long long ll;
typedef unsigned int uint;
typedef pair<ll,ll> pll;
const int nmax = 100005;
const ll linf = 1e17;
const ll mod = 1e9+7;
const int inf = 1e9+7;
const ll lim = 1e4;

int m;
ll n, a[nmax], b[nmax], c[nmax], d[nmax];
ll dp1[nmax], dp2[nmax];
struct {
	ll dp[4*nmax];
	void build(){
		forn(i,4*nmax-1){
			dp[i] = linf;
		}
	}
	void update(int pos ,ll val , int nod , int l , int r){
		if(pos < l || pos > r || l > r)return;
		if(l == r){dp[nod] = min(val,dp[nod]);return;}
		int mid = (l+r)>>1;
		update(pos,val,nod*2,l,mid);
		update(pos,val,nod*2+1,mid+1,r);
		dp[nod] = min(dp[nod*2],dp[nod*2+1]);
	}
	ll query(int lt , int rt , int nod , int l , int r){
		if(lt > r || rt < l || l > r)return linf;
		if(l >= lt && r <= rt)return dp[nod];
		int mid = (l+r)>>1;
		return min(query(lt,rt,nod*2,l,mid),query(lt,rt,nod*2+1,mid+1,r));
	}

}st1, st2;
int main(){
	fast;
	cin >> m >> n;
	vec < int > vc(m);
	forn(i,m){
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		vc[i-1] = c[i];
	}
	sort(all(vc));
	vc.resize(unique(all(vc))-vc.begin());
	forn(i,m){
		c[i] = lower_bound(all(vc),c[i]) - vc.begin() + 1;
	}
	st1.build();
	st2.build();
	forn(i,m){
		int l = lower_bound(all(vc),a[i])- vc.begin()+1;
	   	int r = lower_bound(all(vc),b[i])- vc.begin()+1;	
		if(a[i] == 1){
			dp1[i] = d[i];
		}
		else{
			dp1[i] = d[i] + st1.query(l,r,1,1,m);
		}
		if(b[i] == n){
			dp2[i] = d[i];
		}else{
			dp2[i] = d[i] + st2.query(l,r,1,1,m);
		}
		dp1[i] = min(dp1[i],linf);
		dp2[i] = min(dp2[i],linf);
		st1.update(c[i],dp1[i],1,1,m);
		st2.update(c[i],dp2[i],1,1,m);
	}
	ll rez = linf;
	forn(i,m){
		rez = min(rez , dp1[i] + dp2[i] - d[i]);
	}
	cout << (rez != linf ? rez : -1) << '\n';

}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6656 KB Output is correct
2 Correct 8 ms 6656 KB Output is correct
3 Incorrect 8 ms 6656 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6656 KB Output is correct
2 Correct 8 ms 6656 KB Output is correct
3 Incorrect 8 ms 6656 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6656 KB Output is correct
2 Correct 8 ms 6656 KB Output is correct
3 Incorrect 8 ms 6656 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6656 KB Output is correct
2 Correct 8 ms 6656 KB Output is correct
3 Incorrect 8 ms 6656 KB Output isn't correct
4 Halted 0 ms 0 KB -