답안 #740963

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
740963 2023-05-13T10:33:30 Z pavement Passport (JOI23_passport) C++17
46 / 100
1063 ms 122104 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 6 ms 9684 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Correct 7 ms 9684 KB Output is correct
4 Correct 1063 ms 122104 KB Output is correct
5 Correct 554 ms 83512 KB Output is correct
6 Correct 494 ms 73396 KB Output is correct
7 Correct 359 ms 66004 KB Output is correct
8 Correct 301 ms 76484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 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 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 6 ms 9768 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 9856 KB Output is correct
12 Correct 6 ms 9816 KB Output is correct
13 Correct 6 ms 9812 KB Output is correct
14 Correct 8 ms 9800 KB Output is correct
15 Correct 7 ms 9812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 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 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 6 ms 9768 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 9856 KB Output is correct
12 Correct 6 ms 9816 KB Output is correct
13 Correct 6 ms 9812 KB Output is correct
14 Correct 8 ms 9800 KB Output is correct
15 Correct 7 ms 9812 KB Output is correct
16 Correct 10 ms 10836 KB Output is correct
17 Correct 10 ms 10708 KB Output is correct
18 Correct 10 ms 11248 KB Output is correct
19 Correct 10 ms 11092 KB Output is correct
20 Correct 9 ms 10676 KB Output is correct
21 Correct 9 ms 10708 KB Output is correct
22 Correct 8 ms 10580 KB Output is correct
23 Correct 10 ms 10836 KB Output is correct
24 Correct 10 ms 10868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 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 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 6 ms 9768 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 9856 KB Output is correct
12 Correct 6 ms 9816 KB Output is correct
13 Correct 6 ms 9812 KB Output is correct
14 Correct 8 ms 9800 KB Output is correct
15 Correct 7 ms 9812 KB Output is correct
16 Correct 10 ms 10836 KB Output is correct
17 Correct 10 ms 10708 KB Output is correct
18 Correct 10 ms 11248 KB Output is correct
19 Correct 10 ms 11092 KB Output is correct
20 Correct 9 ms 10676 KB Output is correct
21 Correct 9 ms 10708 KB Output is correct
22 Correct 8 ms 10580 KB Output is correct
23 Correct 10 ms 10836 KB Output is correct
24 Correct 10 ms 10868 KB Output is correct
25 Correct 7 ms 9684 KB Output is correct
26 Correct 5 ms 9684 KB Output is correct
27 Incorrect 12 ms 10964 KB Output isn't correct
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Correct 7 ms 9684 KB Output is correct
4 Correct 1063 ms 122104 KB Output is correct
5 Correct 554 ms 83512 KB Output is correct
6 Correct 494 ms 73396 KB Output is correct
7 Correct 359 ms 66004 KB Output is correct
8 Correct 301 ms 76484 KB Output is correct
9 Correct 6 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 9684 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 6 ms 9768 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 9856 KB Output is correct
20 Correct 6 ms 9816 KB Output is correct
21 Correct 6 ms 9812 KB Output is correct
22 Correct 8 ms 9800 KB Output is correct
23 Correct 7 ms 9812 KB Output is correct
24 Correct 10 ms 10836 KB Output is correct
25 Correct 10 ms 10708 KB Output is correct
26 Correct 10 ms 11248 KB Output is correct
27 Correct 10 ms 11092 KB Output is correct
28 Correct 9 ms 10676 KB Output is correct
29 Correct 9 ms 10708 KB Output is correct
30 Correct 8 ms 10580 KB Output is correct
31 Correct 10 ms 10836 KB Output is correct
32 Correct 10 ms 10868 KB Output is correct
33 Correct 7 ms 9684 KB Output is correct
34 Correct 5 ms 9684 KB Output is correct
35 Incorrect 12 ms 10964 KB Output isn't correct
36 Halted 0 ms 0 KB -