Submission #405244

# Submission time Handle Problem Language Result Execution time Memory
405244 2021-05-16T04:12:10 Z saarang123 Pinball (JOI14_pinball) C++17
100 / 100
780 ms 43300 KB
#include <bits/stdc++.h>
using namespace std;
const int MXN = 100 * 1000 + 3;
const long long INF = 0x3f3f3f3f3f3f3f3f;
long long tree[2][(3 * MXN) << 2];
map<int, long long> compress;
int A[MXN], B[MXN], C[MXN], D[MXN];
int N, M;

void build(int v = 1, int tl = 1, int tr = 3 * M) {
	if(tl == tr)
		return tree[0][v] = tree[1][v] = INF, void();
	int tm = (tl + tr) >> 1;
	build(v << 1, tl, tm);
	build(v << 1|1, tm + 1, tr);
}

void update(int v, int tl, int tr, int pos, long long val, int idx) {
	if(tl == tr)
		return tree[idx][v] = min(tree[idx][v], val), void();
	int tm = (tl + tr) >> 1;
	if(pos <= tm)
		update(v << 1, tl, tm, pos, val, idx);
	else
		update(v << 1|1, tm + 1, tr, pos, val, idx);
	tree[idx][v] = min(tree[idx][v << 1], tree[idx][v << 1|1]);
}

void upd(int pos, long long val, int idx) {
	update(1, 1, 3 * M, pos, val, idx);
}

long long query(int v, int tl, int tr, int l, int r, int idx) {
	if(l > r) return INF;
	if(l <= tl && tr <= r)
		return tree[idx][v];
	int tm = (tl + tr) >> 1;
	return min(query(v << 1, tl, tm, l, min(tm, r), idx),
				query(v << 1|1, tm + 1, tr, max(tm + 1, l), r, idx));
}

long long query(int l, int r, int idx) {
	return query(1, 1, 3 * M, l, r, idx);
}

signed main() {
    std::ios::sync_with_stdio(0);
    std::cout.tie(0);
    std::cin.tie(0);
    cin >> M >> N;
    compress[1] = compress[N] = 0;
    for(int i = 1; i <= M; ++i) {
    	cin >> A[i] >> B[i] >> C[i] >> D[i];
    	compress[A[i]] = compress[B[i]] = compress[C[i]] = 0;
    }
    int t = 0;
    for(auto &[u, v] : compress)
    	v = ++t;

    memset(tree, 0x7f, sizeof tree);
    long long ans = INF;
    upd(compress[1], 0, 0);
    upd(compress[N], 0, 1);
    for(int i = 1; i <= M; i++) {
    	long long prefix = query(compress[A[i]], compress[B[i]], 0);
    	long long suffix = query(compress[A[i]], compress[B[i]], 1);
    	ans = min(ans, prefix + D[i] + suffix);
    	upd(compress[C[i]], prefix + D[i], 0);
    	upd(compress[C[i]], suffix + D[i], 1);
    }
    cout << (ans >= INF ? -1 : ans) << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19020 KB Output is correct
2 Correct 9 ms 19088 KB Output is correct
3 Correct 9 ms 19020 KB Output is correct
4 Correct 9 ms 19020 KB Output is correct
5 Correct 9 ms 19024 KB Output is correct
6 Correct 9 ms 19024 KB Output is correct
7 Correct 9 ms 19116 KB Output is correct
8 Correct 9 ms 19000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19020 KB Output is correct
2 Correct 9 ms 19088 KB Output is correct
3 Correct 9 ms 19020 KB Output is correct
4 Correct 9 ms 19020 KB Output is correct
5 Correct 9 ms 19024 KB Output is correct
6 Correct 9 ms 19024 KB Output is correct
7 Correct 9 ms 19116 KB Output is correct
8 Correct 9 ms 19000 KB Output is correct
9 Correct 11 ms 19020 KB Output is correct
10 Correct 9 ms 19020 KB Output is correct
11 Correct 9 ms 19020 KB Output is correct
12 Correct 9 ms 19052 KB Output is correct
13 Correct 9 ms 19148 KB Output is correct
14 Correct 10 ms 19052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19020 KB Output is correct
2 Correct 9 ms 19088 KB Output is correct
3 Correct 9 ms 19020 KB Output is correct
4 Correct 9 ms 19020 KB Output is correct
5 Correct 9 ms 19024 KB Output is correct
6 Correct 9 ms 19024 KB Output is correct
7 Correct 9 ms 19116 KB Output is correct
8 Correct 9 ms 19000 KB Output is correct
9 Correct 11 ms 19020 KB Output is correct
10 Correct 9 ms 19020 KB Output is correct
11 Correct 9 ms 19020 KB Output is correct
12 Correct 9 ms 19052 KB Output is correct
13 Correct 9 ms 19148 KB Output is correct
14 Correct 10 ms 19052 KB Output is correct
15 Correct 10 ms 19024 KB Output is correct
16 Correct 10 ms 19088 KB Output is correct
17 Correct 12 ms 19148 KB Output is correct
18 Correct 12 ms 19088 KB Output is correct
19 Correct 14 ms 19276 KB Output is correct
20 Correct 11 ms 19148 KB Output is correct
21 Correct 10 ms 19152 KB Output is correct
22 Correct 12 ms 19288 KB Output is correct
23 Correct 11 ms 19360 KB Output is correct
24 Correct 11 ms 19296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19020 KB Output is correct
2 Correct 9 ms 19088 KB Output is correct
3 Correct 9 ms 19020 KB Output is correct
4 Correct 9 ms 19020 KB Output is correct
5 Correct 9 ms 19024 KB Output is correct
6 Correct 9 ms 19024 KB Output is correct
7 Correct 9 ms 19116 KB Output is correct
8 Correct 9 ms 19000 KB Output is correct
9 Correct 11 ms 19020 KB Output is correct
10 Correct 9 ms 19020 KB Output is correct
11 Correct 9 ms 19020 KB Output is correct
12 Correct 9 ms 19052 KB Output is correct
13 Correct 9 ms 19148 KB Output is correct
14 Correct 10 ms 19052 KB Output is correct
15 Correct 10 ms 19024 KB Output is correct
16 Correct 10 ms 19088 KB Output is correct
17 Correct 12 ms 19148 KB Output is correct
18 Correct 12 ms 19088 KB Output is correct
19 Correct 14 ms 19276 KB Output is correct
20 Correct 11 ms 19148 KB Output is correct
21 Correct 10 ms 19152 KB Output is correct
22 Correct 12 ms 19288 KB Output is correct
23 Correct 11 ms 19360 KB Output is correct
24 Correct 11 ms 19296 KB Output is correct
25 Correct 46 ms 20592 KB Output is correct
26 Correct 134 ms 23992 KB Output is correct
27 Correct 391 ms 29068 KB Output is correct
28 Correct 240 ms 24640 KB Output is correct
29 Correct 257 ms 27424 KB Output is correct
30 Correct 342 ms 25660 KB Output is correct
31 Correct 685 ms 35040 KB Output is correct
32 Correct 558 ms 32084 KB Output is correct
33 Correct 69 ms 23832 KB Output is correct
34 Correct 327 ms 31280 KB Output is correct
35 Correct 329 ms 43188 KB Output is correct
36 Correct 780 ms 43292 KB Output is correct
37 Correct 646 ms 43300 KB Output is correct
38 Correct 569 ms 43276 KB Output is correct