답안 #156483

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
156483 2019-10-06T07:28:52 Z nvmdava Pinball (JOI14_pinball) C++17
0 / 100
2 ms 504 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);
	}
	cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 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 384 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Incorrect 2 ms 504 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 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 384 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Incorrect 2 ms 504 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 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 384 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Incorrect 2 ms 504 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 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 384 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Incorrect 2 ms 504 KB Output isn't correct
8 Halted 0 ms 0 KB -