답안 #713789

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
713789 2023-03-23T04:11:20 Z pavement 치료 계획 (JOI20_treatment) C++17
100 / 100
2021 ms 302736 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
#define g4(a) get<4>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using db = double;
using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using iii = tuple<int, int, int>;
using iiii = tuple<int, int, int, int>;
using iiiii = tuple<int, int, int, int, int>;
template<class key, class value = null_type, class cmp = less<key> >
using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

int N, M, ans = (int)1e16, T[100005], L[100005], R[100005], C[100005], dist[100005], discT[100005];
bool seen[100005];
vector<int> all, dvec;
vector<ii> arr[2][100005];
priority_queue<iiiii, vector<iiiii>, greater<iiiii> > pq;

struct node {
	node *left, *right;
	int S, E;
	set<ii> val;
	node(int _s, int _e, vector<ii> arr[]) : S(_s), E(_e) {
		if (S == E) {
			for (auto i : arr[S]) {
				val.insert(i);
			}
			return;
		}
		int M = (S + E) >> 1;
		left = new node(S, M, arr);
		right = new node(M + 1, E, arr);
		for (auto cval : {left->val, right->val})
			for (auto i : cval) {
				val.insert(i);
			}
	}
	void get_all(int l, int r, int x, int y) {
		if (l > E || r < S) return;
		if (l <= S && E <= r) {
			vector<set<ii>::iterator> to_del;
			for (auto it = val.lower_bound(mp(x, 0ll)); it != val.end() && it->first <= y; ++it) {
				if (!seen[it->second]) {
					all.pb(it->second);
				}
				to_del.pb(it);
			}
			for (auto it : to_del) {
				val.erase(it);
			}
			return;
		}
		left->get_all(l, r, x, y);
		right->get_all(l, r, x, y);
	}
} *root[2];

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N >> M;
	for (int i = 1; i <= M; i++) {
		cin >> T[i] >> L[i] >> R[i] >> C[i];
		dvec.pb(T[i]);
	}
	sort(dvec.begin(), dvec.end());
	dvec.erase(unique(dvec.begin(), dvec.end()), dvec.end());
	for (int i = 1; i <= M; i++) {
		discT[i] = lower_bound(dvec.begin(), dvec.end(), T[i]) - dvec.begin() + 1;
		arr[0][discT[i]].eb(L[i] - T[i], i);
		arr[1][discT[i]].eb(L[i] + T[i], i);
	}
	root[0] = new node(1, M, arr[0]);
	root[1] = new node(1, M, arr[1]);
	for (int i = 1; i <= M; i++) {
		if (L[i] == 1) {
			dist[i] = 0;
			pq.emplace(C[i], 1, discT[i], 1 + R[i] - T[i], 0);
			pq.emplace(C[i], discT[i], M, 1 + R[i] + T[i], 1);
			seen[i] = 1;
		} else {
			dist[i] = (int)1e16;
		}
	}
	while (!pq.empty()) {
		auto [d, l, r, y, ty] = pq.top();
		pq.pop();
		auto proc = [&](int v) {
			//~ cout << "PROC " << v << ' ' << d << '\n';
			pq.emplace(d + C[v], 1, discT[v], 1 + R[v] - T[v], 0);
			pq.emplace(d + C[v], discT[v], M, 1 + R[v] + T[v], 1);
			seen[v] = 1;
		};
		all.clear();
		root[ty]->get_all(l, r, (int)-1e16, y);
		for (auto i : all) {
			//~ cout << "INRANGE " << l << ' ' << r << ' ' << x << ' ' << y << ' ' << d << '\n';
			dist[i] = d;
			proc(i);
		}
	}
	for (int i = 1; i <= M; i++) {
		if (R[i] == N) {
			//~ cout << "@ " << i << ' ' << dist[i] + C[i] << '\n';
			ans = min(ans, dist[i] + C[i]);
		}
	}
	if (ans >= (int)1e16) cout << "-1\n";
	else cout << ans << '\n';
}

Compilation message

treatment.cpp:73:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   73 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1504 ms 292452 KB Output is correct
2 Correct 1561 ms 292408 KB Output is correct
3 Correct 1511 ms 291428 KB Output is correct
4 Correct 1527 ms 291664 KB Output is correct
5 Correct 1474 ms 299768 KB Output is correct
6 Correct 1525 ms 292436 KB Output is correct
7 Correct 1592 ms 292344 KB Output is correct
8 Correct 1537 ms 292512 KB Output is correct
9 Correct 1458 ms 292372 KB Output is correct
10 Correct 1442 ms 292256 KB Output is correct
11 Correct 1617 ms 302736 KB Output is correct
12 Correct 1593 ms 300432 KB Output is correct
13 Correct 1632 ms 297964 KB Output is correct
14 Correct 1586 ms 297860 KB Output is correct
15 Correct 1670 ms 292592 KB Output is correct
16 Correct 2021 ms 292324 KB Output is correct
17 Correct 1535 ms 291592 KB Output is correct
18 Correct 1560 ms 299396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5032 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 3 ms 5076 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 4 ms 5036 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 3 ms 5032 KB Output is correct
8 Correct 3 ms 5076 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 3 ms 5076 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 4 ms 5040 KB Output is correct
14 Correct 3 ms 5036 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 3 ms 5076 KB Output is correct
17 Correct 3 ms 5016 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 4 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5032 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 3 ms 5076 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 4 ms 5036 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 3 ms 5032 KB Output is correct
8 Correct 3 ms 5076 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 3 ms 5076 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 4 ms 5040 KB Output is correct
14 Correct 3 ms 5036 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 3 ms 5076 KB Output is correct
17 Correct 3 ms 5016 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 4 ms 5076 KB Output is correct
20 Correct 41 ms 16552 KB Output is correct
21 Correct 42 ms 16556 KB Output is correct
22 Correct 38 ms 16616 KB Output is correct
23 Correct 37 ms 16664 KB Output is correct
24 Correct 42 ms 16844 KB Output is correct
25 Correct 46 ms 16552 KB Output is correct
26 Correct 43 ms 16428 KB Output is correct
27 Correct 42 ms 16548 KB Output is correct
28 Correct 42 ms 16764 KB Output is correct
29 Correct 43 ms 16500 KB Output is correct
30 Correct 31 ms 16668 KB Output is correct
31 Correct 32 ms 16464 KB Output is correct
32 Correct 54 ms 17104 KB Output is correct
33 Correct 45 ms 17192 KB Output is correct
34 Correct 47 ms 16452 KB Output is correct
35 Correct 41 ms 17068 KB Output is correct
36 Correct 41 ms 17100 KB Output is correct
37 Correct 47 ms 16464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1504 ms 292452 KB Output is correct
2 Correct 1561 ms 292408 KB Output is correct
3 Correct 1511 ms 291428 KB Output is correct
4 Correct 1527 ms 291664 KB Output is correct
5 Correct 1474 ms 299768 KB Output is correct
6 Correct 1525 ms 292436 KB Output is correct
7 Correct 1592 ms 292344 KB Output is correct
8 Correct 1537 ms 292512 KB Output is correct
9 Correct 1458 ms 292372 KB Output is correct
10 Correct 1442 ms 292256 KB Output is correct
11 Correct 1617 ms 302736 KB Output is correct
12 Correct 1593 ms 300432 KB Output is correct
13 Correct 1632 ms 297964 KB Output is correct
14 Correct 1586 ms 297860 KB Output is correct
15 Correct 1670 ms 292592 KB Output is correct
16 Correct 2021 ms 292324 KB Output is correct
17 Correct 1535 ms 291592 KB Output is correct
18 Correct 1560 ms 299396 KB Output is correct
19 Correct 3 ms 5032 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 3 ms 5076 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 4 ms 5036 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 5032 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 3 ms 5076 KB Output is correct
29 Correct 3 ms 5076 KB Output is correct
30 Correct 4 ms 5076 KB Output is correct
31 Correct 4 ms 5040 KB Output is correct
32 Correct 3 ms 5036 KB Output is correct
33 Correct 3 ms 5076 KB Output is correct
34 Correct 3 ms 5076 KB Output is correct
35 Correct 3 ms 5016 KB Output is correct
36 Correct 3 ms 5076 KB Output is correct
37 Correct 4 ms 5076 KB Output is correct
38 Correct 41 ms 16552 KB Output is correct
39 Correct 42 ms 16556 KB Output is correct
40 Correct 38 ms 16616 KB Output is correct
41 Correct 37 ms 16664 KB Output is correct
42 Correct 42 ms 16844 KB Output is correct
43 Correct 46 ms 16552 KB Output is correct
44 Correct 43 ms 16428 KB Output is correct
45 Correct 42 ms 16548 KB Output is correct
46 Correct 42 ms 16764 KB Output is correct
47 Correct 43 ms 16500 KB Output is correct
48 Correct 31 ms 16668 KB Output is correct
49 Correct 32 ms 16464 KB Output is correct
50 Correct 54 ms 17104 KB Output is correct
51 Correct 45 ms 17192 KB Output is correct
52 Correct 47 ms 16452 KB Output is correct
53 Correct 41 ms 17068 KB Output is correct
54 Correct 41 ms 17100 KB Output is correct
55 Correct 47 ms 16464 KB Output is correct
56 Correct 1107 ms 289836 KB Output is correct
57 Correct 1104 ms 290388 KB Output is correct
58 Correct 1112 ms 289588 KB Output is correct
59 Correct 1138 ms 290020 KB Output is correct
60 Correct 1212 ms 291132 KB Output is correct
61 Correct 1090 ms 289524 KB Output is correct
62 Correct 1125 ms 289812 KB Output is correct
63 Correct 1051 ms 290244 KB Output is correct
64 Correct 970 ms 290184 KB Output is correct
65 Correct 1477 ms 292652 KB Output is correct
66 Correct 1121 ms 291056 KB Output is correct
67 Correct 1641 ms 289272 KB Output is correct
68 Correct 1369 ms 289216 KB Output is correct
69 Correct 1372 ms 288756 KB Output is correct
70 Correct 1564 ms 289320 KB Output is correct
71 Correct 1486 ms 289384 KB Output is correct
72 Correct 1281 ms 289312 KB Output is correct
73 Correct 1562 ms 289300 KB Output is correct
74 Correct 787 ms 289300 KB Output is correct
75 Correct 825 ms 289288 KB Output is correct
76 Correct 1263 ms 298940 KB Output is correct
77 Correct 1314 ms 299556 KB Output is correct
78 Correct 1419 ms 298692 KB Output is correct
79 Correct 1527 ms 289380 KB Output is correct
80 Correct 1626 ms 288452 KB Output is correct
81 Correct 802 ms 289388 KB Output is correct
82 Correct 1456 ms 287924 KB Output is correct
83 Correct 1442 ms 288404 KB Output is correct
84 Correct 1499 ms 288528 KB Output is correct
85 Correct 1152 ms 289184 KB Output is correct
86 Correct 1147 ms 289352 KB Output is correct
87 Correct 1242 ms 289228 KB Output is correct
88 Correct 1179 ms 289428 KB Output is correct
89 Correct 1213 ms 289308 KB Output is correct
90 Correct 1339 ms 299480 KB Output is correct
91 Correct 1358 ms 293324 KB Output is correct
92 Correct 1214 ms 289188 KB Output is correct
93 Correct 1502 ms 289300 KB Output is correct
94 Correct 1513 ms 289208 KB Output is correct
95 Correct 1451 ms 289252 KB Output is correct
96 Correct 1353 ms 299604 KB Output is correct
97 Correct 1303 ms 299492 KB Output is correct
98 Correct 1296 ms 299556 KB Output is correct
99 Correct 1310 ms 299616 KB Output is correct
100 Correct 1290 ms 299460 KB Output is correct
101 Correct 1302 ms 299468 KB Output is correct
102 Correct 1400 ms 299516 KB Output is correct
103 Correct 1295 ms 289256 KB Output is correct