Submission #239799

# Submission time Handle Problem Language Result Execution time Memory
239799 2020-06-17T10:12:35 Z Knps4422 Pinball (JOI14_pinball) C++14
100 / 100
232 ms 15608 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]+1)- vc.begin();	
		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';

}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6656 KB Output is correct
2 Correct 7 ms 6528 KB Output is correct
3 Correct 7 ms 6784 KB Output is correct
4 Correct 8 ms 6656 KB Output is correct
5 Correct 8 ms 6656 KB Output is correct
6 Correct 7 ms 6656 KB Output is correct
7 Correct 8 ms 6656 KB Output is correct
8 Correct 7 ms 6656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6656 KB Output is correct
2 Correct 7 ms 6528 KB Output is correct
3 Correct 7 ms 6784 KB Output is correct
4 Correct 8 ms 6656 KB Output is correct
5 Correct 8 ms 6656 KB Output is correct
6 Correct 7 ms 6656 KB Output is correct
7 Correct 8 ms 6656 KB Output is correct
8 Correct 7 ms 6656 KB Output is correct
9 Correct 7 ms 6656 KB Output is correct
10 Correct 8 ms 6656 KB Output is correct
11 Correct 8 ms 6656 KB Output is correct
12 Correct 8 ms 6656 KB Output is correct
13 Correct 8 ms 6656 KB Output is correct
14 Correct 8 ms 6656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6656 KB Output is correct
2 Correct 7 ms 6528 KB Output is correct
3 Correct 7 ms 6784 KB Output is correct
4 Correct 8 ms 6656 KB Output is correct
5 Correct 8 ms 6656 KB Output is correct
6 Correct 7 ms 6656 KB Output is correct
7 Correct 8 ms 6656 KB Output is correct
8 Correct 7 ms 6656 KB Output is correct
9 Correct 7 ms 6656 KB Output is correct
10 Correct 8 ms 6656 KB Output is correct
11 Correct 8 ms 6656 KB Output is correct
12 Correct 8 ms 6656 KB Output is correct
13 Correct 8 ms 6656 KB Output is correct
14 Correct 8 ms 6656 KB Output is correct
15 Correct 7 ms 6656 KB Output is correct
16 Correct 8 ms 6656 KB Output is correct
17 Correct 9 ms 6656 KB Output is correct
18 Correct 9 ms 6656 KB Output is correct
19 Correct 10 ms 6784 KB Output is correct
20 Correct 9 ms 6688 KB Output is correct
21 Correct 8 ms 6656 KB Output is correct
22 Correct 9 ms 6656 KB Output is correct
23 Correct 9 ms 6656 KB Output is correct
24 Correct 10 ms 6656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6656 KB Output is correct
2 Correct 7 ms 6528 KB Output is correct
3 Correct 7 ms 6784 KB Output is correct
4 Correct 8 ms 6656 KB Output is correct
5 Correct 8 ms 6656 KB Output is correct
6 Correct 7 ms 6656 KB Output is correct
7 Correct 8 ms 6656 KB Output is correct
8 Correct 7 ms 6656 KB Output is correct
9 Correct 7 ms 6656 KB Output is correct
10 Correct 8 ms 6656 KB Output is correct
11 Correct 8 ms 6656 KB Output is correct
12 Correct 8 ms 6656 KB Output is correct
13 Correct 8 ms 6656 KB Output is correct
14 Correct 8 ms 6656 KB Output is correct
15 Correct 7 ms 6656 KB Output is correct
16 Correct 8 ms 6656 KB Output is correct
17 Correct 9 ms 6656 KB Output is correct
18 Correct 9 ms 6656 KB Output is correct
19 Correct 10 ms 6784 KB Output is correct
20 Correct 9 ms 6688 KB Output is correct
21 Correct 8 ms 6656 KB Output is correct
22 Correct 9 ms 6656 KB Output is correct
23 Correct 9 ms 6656 KB Output is correct
24 Correct 10 ms 6656 KB Output is correct
25 Correct 25 ms 7424 KB Output is correct
26 Correct 55 ms 8824 KB Output is correct
27 Correct 157 ms 12708 KB Output is correct
28 Correct 172 ms 15480 KB Output is correct
29 Correct 113 ms 11160 KB Output is correct
30 Correct 195 ms 15608 KB Output is correct
31 Correct 228 ms 15608 KB Output is correct
32 Correct 221 ms 15608 KB Output is correct
33 Correct 35 ms 8312 KB Output is correct
34 Correct 101 ms 11128 KB Output is correct
35 Correct 159 ms 15608 KB Output is correct
36 Correct 232 ms 15480 KB Output is correct
37 Correct 200 ms 15608 KB Output is correct
38 Correct 196 ms 15480 KB Output is correct