Submission #156484

# Submission time Handle Problem Language Result Execution time Memory
156484 2019-10-06T07:29:32 Z nvmdava Pinball (JOI14_pinball) C++17
100 / 100
640 ms 98460 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
 
#define N 100005
#define MOD 1000000007
#define INF 0x3f3f3f3f3f3f3f3f

struct Node{
	Node *l = NULL, *r = NULL;
	ll val = INF;
	int L, R;

	Node(int lll, int rrr){
		L = lll;
		R = rrr;
	}

	void update(int x, ll t){
		if(t > INF) return;
		if(L == R){
			val = min(val, t);
			return;
		}
		int M = (L + R) >> 1;
		if(M >= x){
			if(l == NULL)
				l = new Node(L, M);
			l -> update(x, t);
		} else {
			if(r == NULL)
				r = new Node(M + 1, R);
			r -> update(x, t);
		}

		ll v1, v2;
		if(l == NULL)
			v1 = INF;
		else
			v1 = l -> val;

		if(r == NULL)
			v2 = INF;
		else
			v2 = r -> val;
		
		val = min(v1, v2);
	}

	ll query(int LL, int RR){
		if(LL <= L && R <= RR)
			return val;
		if(LL > R || L > RR)
			return INF;

		ll v1, v2;

		if(l == NULL)
			v1 = INF;
		else
			v1 = l -> query(LL, RR);

		if(r == NULL)
			v2 = INF;
		else 
			v2 = r -> query(LL, RR);
		return min(v1, v2);
	}



} *a = NULL, *b = NULL;

ll ans = INF;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
 
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	int m, n;
	cin>>m>>n;
	a = new Node(1, n);
	b = new Node(1, n);
	a -> update(1, 0);
	b -> update(n, 0);

	for(int i = 1; i <= m; i++){
		int A, B, C, D;
		cin>>A>>B>>C>>D;

		ll av = a -> query(A, B);
		ll bv = b -> query(A, B);
		ans = min(ans, av + bv + D);

		a -> update(C, av + D);
		b -> update(C, bv + D);
	}
	if(ans == INF)
		cout<<-1;
	else
		cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 352 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 2 ms 424 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 352 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 2 ms 424 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 6 ms 1500 KB Output is correct
18 Correct 4 ms 504 KB Output is correct
19 Correct 5 ms 1272 KB Output is correct
20 Correct 6 ms 1272 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 4 ms 764 KB Output is correct
23 Correct 5 ms 1272 KB Output is correct
24 Correct 4 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 352 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 2 ms 424 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 6 ms 1500 KB Output is correct
18 Correct 4 ms 504 KB Output is correct
19 Correct 5 ms 1272 KB Output is correct
20 Correct 6 ms 1272 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 4 ms 764 KB Output is correct
23 Correct 5 ms 1272 KB Output is correct
24 Correct 4 ms 1016 KB Output is correct
25 Correct 31 ms 5496 KB Output is correct
26 Correct 102 ms 21396 KB Output is correct
27 Correct 361 ms 49520 KB Output is correct
28 Correct 331 ms 5496 KB Output is correct
29 Correct 205 ms 42116 KB Output is correct
30 Correct 497 ms 19340 KB Output is correct
31 Correct 640 ms 98460 KB Output is correct
32 Correct 637 ms 79412 KB Output is correct
33 Correct 34 ms 8696 KB Output is correct
34 Correct 85 ms 19064 KB Output is correct
35 Correct 211 ms 65784 KB Output is correct
36 Correct 387 ms 80120 KB Output is correct
37 Correct 181 ms 39516 KB Output is correct
38 Correct 182 ms 41216 KB Output is correct