답안 #871373

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
871373 2023-11-10T16:38:55 Z serifefedartar Pinball (JOI14_pinball) C++17
100 / 100
337 ms 22516 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9+9;
const ll LOGN = 22; 
const ll MAXN = 4e5 + 100;

vector<int> cc;
struct Machine {
	int l, r, centr;
	ll cost;
	void read() {
		cin >> l >> r >> centr >> cost;
		cc.push_back(l);
		cc.push_back(r);
		cc.push_back(centr);
	}
	Machine(int _l, int _r, int _centr, ll _cost) : l(_l), r(_r), centr(_centr), cost(_cost) { }
	Machine() { }
};

vector<Machine> v;
int n;
ll sg[4*MAXN], to_right[MAXN], to_left[MAXN];
void init(int k, int a, int b) {
	if (a == b) {
		sg[k] = 1e16;
		return ;
	}
	init(2*k, a, (a+b)/2);
	init(2*k+1, (a+b)/2+1, b);
	sg[k] = min(sg[2*k], sg[2*k+1]);
}

void update(int k, int a, int b, int plc, ll val) {
	if (b < plc || a > plc)
		return ;
	if (a == b) {
		sg[k] = min(sg[k], val);
		return ;
	}
	update(2*k, a, (a+b)/2, plc, val);
	update(2*k+1, (a+b)/2+1, b, plc, val);
	sg[k] = min(sg[2*k], sg[2*k+1]);
}

ll query(int k, int a, int b, int q_l, int q_r) {
	if (q_l > b || q_r < a)
		return 1e16;
	if (q_l <= a && b <= q_r)
		return sg[k];
	return min(query(2*k, a, (a+b)/2, q_l, q_r),
				query(2*k+1, (a+b)/2+1, b, q_l, q_r));
}

int index(int k) {
	return lower_bound(cc.begin(), cc.end(), k) - cc.begin();
}

int main() {
	int M, N;
	cin >> M >> N;

	v = vector<Machine>(M+1);
	for (int i = 1; i <= M; i++)
		v[i].read();
	sort(cc.begin(), cc.end());
	cc.erase(unique(cc.begin(), cc.end()), cc.end());
	n = cc.size();

	init(1, 1, n);
	for (int i = 1; i <= M; i++) {
		ll Q = query(1, 1, n, index(v[i].l), index(v[i].r));
		if (v[i].l == 1)
			Q = 0;

		to_left[i] = Q + v[i].cost;
		update(1, 1, n, index(v[i].centr), to_left[i]);
	}

	init(1, 1, n);
	for (int i = 1; i <= M; i++) {
		ll Q = query(1, 1, n, index(v[i].l), index(v[i].r));
		if (v[i].r == N)
			Q = 0;

		to_right[i] = Q + v[i].cost;
		update(1, 1, n, index(v[i].centr), to_right[i]);
	}

	ll mn = 1e16;
	for (int i = 1; i <= M; i++)
		mn = min(mn, to_left[i] + to_right[i] - v[i].cost);

	if (mn >= 1e14)
		mn = -1;
	cout << mn << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 3 ms 4444 KB Output is correct
18 Correct 3 ms 4444 KB Output is correct
19 Correct 3 ms 4440 KB Output is correct
20 Correct 3 ms 4444 KB Output is correct
21 Correct 2 ms 4444 KB Output is correct
22 Correct 3 ms 4440 KB Output is correct
23 Correct 3 ms 4444 KB Output is correct
24 Correct 3 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 3 ms 4444 KB Output is correct
18 Correct 3 ms 4444 KB Output is correct
19 Correct 3 ms 4440 KB Output is correct
20 Correct 3 ms 4444 KB Output is correct
21 Correct 2 ms 4444 KB Output is correct
22 Correct 3 ms 4440 KB Output is correct
23 Correct 3 ms 4444 KB Output is correct
24 Correct 3 ms 4444 KB Output is correct
25 Correct 25 ms 7004 KB Output is correct
26 Correct 74 ms 9780 KB Output is correct
27 Correct 199 ms 11280 KB Output is correct
28 Correct 217 ms 10176 KB Output is correct
29 Correct 151 ms 10568 KB Output is correct
30 Correct 261 ms 12228 KB Output is correct
31 Correct 304 ms 14288 KB Output is correct
32 Correct 297 ms 16536 KB Output is correct
33 Correct 44 ms 8228 KB Output is correct
34 Correct 148 ms 14588 KB Output is correct
35 Correct 239 ms 22276 KB Output is correct
36 Correct 337 ms 22460 KB Output is correct
37 Correct 297 ms 22516 KB Output is correct
38 Correct 295 ms 22468 KB Output is correct