답안 #282859

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
282859 2020-08-25T05:13:22 Z oolimry Pinball (JOI14_pinball) C++14
51 / 100
959 ms 524292 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#define L first
#define R second
using namespace std;
typedef long long lint;
typedef pair<int,int> ii;
const lint inf = 1e17;

struct node{
	int s, e, m;
	lint val;
	node *l = nullptr, *r = nullptr;
	
	node(int S, int E){
		s = S, e = E, m = (s+e)/2;
		val = inf;
		
	}
	
	void create(){
		if(s != e){
			l = new node(s,m);
			r = new node(m+1,e);
		}
	}
	
	void update(int P, lint V){
		val = min(val, V);
		if(s == e) return;
		else if(P <= m){
			if(l == nullptr) create();
			l->update(P,V);
		}
		else{
			if(r == nullptr) create();
			r->update(P,V);
			
		}
	}
	
	lint query(int S, int E){
		if(s == S && E == e) return val;
		else{
			if(l == nullptr) create();
			if(E <= m) return l->query(S,E);
			else if(S >= m+1) return r->query(S,E);
			else return min(l->query(S,m), r->query(m+1,E));
		}
	}
} *Left, *Right;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	int n, len; cin >> n >> len;
	Left = new node(1, len), Right = new node(1, len);
	Left->update(1, 0); Right->update(len, 0);
	
	lint ans = inf;
	
	for(int i = 0;i < n;i++){
		int L, R, M, cost; cin >> L >> R >> M >> cost;
		
		lint fromLeft = Left->query(L, R);
		lint fromRight = Right->query(L, R);
		
		ans = min(ans, fromLeft + fromRight + cost);
				
		Left->update(M, fromLeft + cost);
		Right->update(M, fromRight + cost);
	}
	
	if(ans == inf) ans = -1;
	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 2 ms 1024 KB Output is correct
12 Correct 3 ms 2304 KB Output is correct
13 Correct 3 ms 2432 KB Output is correct
14 Correct 3 ms 2560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 2 ms 1024 KB Output is correct
12 Correct 3 ms 2304 KB Output is correct
13 Correct 3 ms 2432 KB Output is correct
14 Correct 3 ms 2560 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 2 ms 1536 KB Output is correct
17 Correct 7 ms 3840 KB Output is correct
18 Correct 2 ms 640 KB Output is correct
19 Correct 12 ms 8704 KB Output is correct
20 Correct 5 ms 2688 KB Output is correct
21 Correct 4 ms 2688 KB Output is correct
22 Correct 12 ms 8576 KB Output is correct
23 Correct 13 ms 9856 KB Output is correct
24 Correct 13 ms 9984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 2 ms 1024 KB Output is correct
12 Correct 3 ms 2304 KB Output is correct
13 Correct 3 ms 2432 KB Output is correct
14 Correct 3 ms 2560 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 2 ms 1536 KB Output is correct
17 Correct 7 ms 3840 KB Output is correct
18 Correct 2 ms 640 KB Output is correct
19 Correct 12 ms 8704 KB Output is correct
20 Correct 5 ms 2688 KB Output is correct
21 Correct 4 ms 2688 KB Output is correct
22 Correct 12 ms 8576 KB Output is correct
23 Correct 13 ms 9856 KB Output is correct
24 Correct 13 ms 9984 KB Output is correct
25 Correct 50 ms 15352 KB Output is correct
26 Correct 227 ms 82532 KB Output is correct
27 Correct 555 ms 141304 KB Output is correct
28 Correct 227 ms 6648 KB Output is correct
29 Correct 468 ms 168568 KB Output is correct
30 Correct 485 ms 33532 KB Output is correct
31 Correct 959 ms 304760 KB Output is correct
32 Correct 870 ms 206072 KB Output is correct
33 Correct 118 ms 70660 KB Output is correct
34 Correct 581 ms 296696 KB Output is correct
35 Runtime error 754 ms 524292 KB Execution killed with signal 9
36 Halted 0 ms 0 KB -