답안 #740965

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
740965 2023-05-13T10:34:20 Z pavement Passport (JOI23_passport) C++17
100 / 100
1168 ms 134964 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, Q, _idx, L[400005], R[400005], distL[400005], distR[400005], distC[400005], mpp[400005];
vector<ii> adj[400005];
priority_queue<ii, vector<ii>, greater<ii> > pq;

void dijk(int dist[]) {
	for (int i = 1; i <= _idx; i++) {
		pq.emplace(dist[i], i);
	}
	while (!pq.empty()) {
		auto [d, v] = pq.top();
		pq.pop();
		if (d != dist[v]) continue;
		//~ cout << "@ " << v << ' ' << dist[v] << '\n';
		for (auto [u, w] : adj[v]) {
			if (d + w < dist[u]) {
				dist[u] = d + w;
				pq.emplace(dist[u], u);
			}
		}
	}
}

struct node {
	node *left, *right;
	int S, E, idx;
	node(int _s, int _e) : S(_s), E(_e), idx(++_idx) {
		if (S == E) {
			mpp[S] = idx;
			return;
		}
		int M = (S + E) >> 1;
		left = new node(S, M);
		right = new node(M + 1, E);
		adj[left->idx].eb(idx, 0);
		adj[right->idx].eb(idx, 0);
	}
	void add(int l, int r, int v) {
		if (l > E || r < S) return;
		if (l <= S && E <= r) {
			//~ cout << "ADD " << idx << ' ' << v << '\n';
			adj[idx].eb(v, 1);
			return;
		}
		left->add(l, r, v);
		right->add(l, r, v);
	}
} *root;

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	root = new node(1, N);
	for (int i = 1; i <= N; i++) {
		cin >> L[i] >> R[i];
		root->add(L[i], R[i], mpp[i]);
	}
	for (int i = 1; i <= _idx; i++) {
		distL[i] = distR[i] = distC[i] = (int)1e9;
	}
	for (int i = 1; i <= N; i++) {
		if (L[i] == 1) distL[mpp[i]] = 0;
		if (R[i] == N) distR[mpp[i]] = 0;
	}
	dijk(distL);
	dijk(distR);
	for (int i = 1; i <= N; i++) {
		//~ cout << distL[mpp[i]] << ' ' << distR[mpp[i]] << '\n';
		distC[mpp[i]] = distL[mpp[i]] + distR[mpp[i]];
	}
	dijk(distC);
	cin >> Q;
	for (int x; Q--; ) {
		cin >> x;
		if (distC[mpp[x]] >= (int)1e9) cout << "-1\n";
		else cout << distC[mpp[x]] + 1 << '\n';
	}
}

Compilation message

passport.cpp:76:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   76 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 6 ms 9652 KB Output is correct
4 Correct 1078 ms 122136 KB Output is correct
5 Correct 541 ms 82644 KB Output is correct
6 Correct 472 ms 72504 KB Output is correct
7 Correct 352 ms 65372 KB Output is correct
8 Correct 262 ms 75808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9812 KB Output is correct
5 Correct 5 ms 9752 KB Output is correct
6 Correct 5 ms 9668 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 6 ms 9812 KB Output is correct
12 Correct 5 ms 9812 KB Output is correct
13 Correct 6 ms 9812 KB Output is correct
14 Correct 5 ms 9884 KB Output is correct
15 Correct 6 ms 9812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9812 KB Output is correct
5 Correct 5 ms 9752 KB Output is correct
6 Correct 5 ms 9668 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 6 ms 9812 KB Output is correct
12 Correct 5 ms 9812 KB Output is correct
13 Correct 6 ms 9812 KB Output is correct
14 Correct 5 ms 9884 KB Output is correct
15 Correct 6 ms 9812 KB Output is correct
16 Correct 10 ms 10836 KB Output is correct
17 Correct 9 ms 10708 KB Output is correct
18 Correct 11 ms 11212 KB Output is correct
19 Correct 10 ms 11092 KB Output is correct
20 Correct 11 ms 10628 KB Output is correct
21 Correct 10 ms 10728 KB Output is correct
22 Correct 8 ms 10580 KB Output is correct
23 Correct 9 ms 10836 KB Output is correct
24 Correct 9 ms 10868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9812 KB Output is correct
5 Correct 5 ms 9752 KB Output is correct
6 Correct 5 ms 9668 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 6 ms 9812 KB Output is correct
12 Correct 5 ms 9812 KB Output is correct
13 Correct 6 ms 9812 KB Output is correct
14 Correct 5 ms 9884 KB Output is correct
15 Correct 6 ms 9812 KB Output is correct
16 Correct 10 ms 10836 KB Output is correct
17 Correct 9 ms 10708 KB Output is correct
18 Correct 11 ms 11212 KB Output is correct
19 Correct 10 ms 11092 KB Output is correct
20 Correct 11 ms 10628 KB Output is correct
21 Correct 10 ms 10728 KB Output is correct
22 Correct 8 ms 10580 KB Output is correct
23 Correct 9 ms 10836 KB Output is correct
24 Correct 9 ms 10868 KB Output is correct
25 Correct 5 ms 9684 KB Output is correct
26 Correct 6 ms 9736 KB Output is correct
27 Correct 11 ms 11000 KB Output is correct
28 Correct 10 ms 10768 KB Output is correct
29 Correct 9 ms 10708 KB Output is correct
30 Correct 10 ms 10788 KB Output is correct
31 Correct 10 ms 10708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 6 ms 9652 KB Output is correct
4 Correct 1078 ms 122136 KB Output is correct
5 Correct 541 ms 82644 KB Output is correct
6 Correct 472 ms 72504 KB Output is correct
7 Correct 352 ms 65372 KB Output is correct
8 Correct 262 ms 75808 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9812 KB Output is correct
13 Correct 5 ms 9752 KB Output is correct
14 Correct 5 ms 9668 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 5 ms 9684 KB Output is correct
19 Correct 6 ms 9812 KB Output is correct
20 Correct 5 ms 9812 KB Output is correct
21 Correct 6 ms 9812 KB Output is correct
22 Correct 5 ms 9884 KB Output is correct
23 Correct 6 ms 9812 KB Output is correct
24 Correct 10 ms 10836 KB Output is correct
25 Correct 9 ms 10708 KB Output is correct
26 Correct 11 ms 11212 KB Output is correct
27 Correct 10 ms 11092 KB Output is correct
28 Correct 11 ms 10628 KB Output is correct
29 Correct 10 ms 10728 KB Output is correct
30 Correct 8 ms 10580 KB Output is correct
31 Correct 9 ms 10836 KB Output is correct
32 Correct 9 ms 10868 KB Output is correct
33 Correct 5 ms 9684 KB Output is correct
34 Correct 6 ms 9736 KB Output is correct
35 Correct 11 ms 11000 KB Output is correct
36 Correct 10 ms 10768 KB Output is correct
37 Correct 9 ms 10708 KB Output is correct
38 Correct 10 ms 10788 KB Output is correct
39 Correct 10 ms 10708 KB Output is correct
40 Correct 1168 ms 131716 KB Output is correct
41 Correct 558 ms 84048 KB Output is correct
42 Correct 672 ms 134556 KB Output is correct
43 Correct 653 ms 134964 KB Output is correct
44 Correct 539 ms 73488 KB Output is correct
45 Correct 556 ms 87944 KB Output is correct
46 Correct 233 ms 38464 KB Output is correct
47 Correct 617 ms 91184 KB Output is correct
48 Correct 719 ms 104652 KB Output is correct