Submission #315548

# Submission time Handle Problem Language Result Execution time Memory
315548 2020-10-23T04:15:29 Z super_j6 Pinball (JOI14_pinball) C++14
100 / 100
89 ms 9468 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second

const ll inf = 0x3f3f3f3f3f3f3f3f;
int n, m;
map<int, ll> dpl;
map<int, ll, greater<int>> dpr;

template<typename T>
void add(T &dp, int x, ll y){
	auto it = dp.insert({x, y}).f;
	y = min(y, it->s), it->s = y;
	if(next(it) != dp.end() && next(it)->s <= y) it = dp.erase(it);
	while(it != dp.begin() && (--it)->s >= y) it = dp.erase(it);
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	
	ll ret = !!~-m * inf;
	dpl[1] = 0, dpl[m] = inf, dpr[1] = inf, dpr[m] = 0;
	for(int i = 0; i < n; i++){
		int l, r, x, y;
		cin >> l >> r >> x >> y;
		ll vl = dpl.lower_bound(l)->s, vr = dpr.lower_bound(r)->s;
		ret = min(ret, vl + vr + y);
		add(dpl, x, vl + y), add(dpr, x, vr + y);
	}
	
	cout << (ret < inf ? ret : -1) << endl;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 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 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 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 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 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 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 7 ms 640 KB Output is correct
26 Correct 19 ms 1152 KB Output is correct
27 Correct 48 ms 2812 KB Output is correct
28 Correct 69 ms 4088 KB Output is correct
29 Correct 35 ms 2296 KB Output is correct
30 Correct 73 ms 4216 KB Output is correct
31 Correct 70 ms 4216 KB Output is correct
32 Correct 69 ms 4216 KB Output is correct
33 Correct 17 ms 1792 KB Output is correct
34 Correct 37 ms 2424 KB Output is correct
35 Correct 89 ms 9468 KB Output is correct
36 Correct 75 ms 4216 KB Output is correct
37 Correct 83 ms 4984 KB Output is correct
38 Correct 89 ms 5648 KB Output is correct