답안 #799427

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
799427 2023-07-31T14:11:38 Z Sohsoh84 통행료 (IOI18_highway) C++17
90 / 100
244 ms 43456 KB
#include "highway.h"
#include <bits/stdc++.h>

using namespace std;

#define sep		' '
#define debug(x)	cerr << #x << ": " << x << endl;
#define all(x)		(x).begin(), (x).end()

const int MAXN = 1e6 + 10;

bool bad[MAXN];
int askcnt = 0;
int from[MAXN], to[MAXN], n, m, par[MAXN], mn;
vector<int> adj[MAXN], dfs_order, fuck, jahel;
int fucking_root, A, B;

inline int f(int ind, int v) {
	return from[ind] ^ to[ind] ^ v;
}

void dfs(int v, int p, int d = 0) {
	dfs_order.push_back(v);
	for (int ind : adj[v]) {
		int u = f(ind, v);
		if (u == p) continue;
		if (bad[u]) continue;

		if (d == mn / A)
			jahel.push_back(v);

		par[u] = ind;
		dfs(u, v, d + 1);
	}
}


inline vector<int> seg(int l, int r) {
	vector<int> ans;
	for (int i = l; i <= r; i++)
		ans.push_back(par[dfs_order[i]]);

	return ans;
}

inline int get(vector<int> vec) {
	askcnt++;
	assert(askcnt <= 90);
	vector<int> W(m);
	for (int i = 0; i < m; i++) W[i] = 1;
	for (int e : fuck)
		W[e] = 0;

	for (int e : vec)
		W[e] = 1;

	return ask(W);
}

inline int getp(vector<int> vec) {
	askcnt++;
	assert(askcnt <= 90);
	vector<int> W(m);
	for (int i = 0; i < m; i++) 
		W[i] = 1;
	for (int e : vec)
		W[e] = 0;

	return ask(W);
}

inline int get(int l, int r) {
	return get(seg(l, r));
}

inline int getp(int l, int r) {
	return getp(seg(l, r));
}

inline int find(int root, int tof = 0) {
	par[root] = -1;
	dfs_order.clear();
	jahel.clear();

	dfs(root, root);

	if (tof) dfs_order = jahel;

	int l = 1, r = int(dfs_order.size()) - 1;

	while (l < r) {
		int mid = (l + r) >> 1;	
		if (getp(1, mid) == mn) r = mid;
		else l = mid + 1;
	}

	return dfs_order[l];

}

int dist[MAXN];

const double Z = 0.5;

inline vector<int> random_spt() {
	vector<int> ans;
	queue<int> q;

	int l = 0, r = n - 1;
	while (l < r) {
		int len = r - l;
		int mid = l + Z * len;
		mid = max(mid, l);
		mid = min(mid, r - 1);

		vector<int> W(m);

		for (int i = 0; i < m; i++)
			if (from[i] <= mid || to[i] <= mid)
				W[i] = 1;

		if (ask(W) == mn) {
			for (int i = l; i <= mid; i++) bad[i] = true;
			l = mid + 1;
		} else r = mid;
	}

	int v = l;
	fucking_root = v;

	memset(dist, 63, sizeof dist);
	q.push(v);
	dist[v] = 0;

	while (!q.empty()) {
		int v = q.front();
		q.pop();

		if (v < fucking_root) continue;

		for (int ind : adj[v]) {
			int u = f(ind, v);
			if (u < fucking_root) continue;
			if (dist[u] > dist[v] + 1) {
				dist[u] = dist[v] + 1;
				q.push(u);
				ans.push_back(ind);
			}
		}
	}

	return ans;
}

void find_pair(int N, std::vector<int> U, std::vector<int> V, int A_, int B_) {
	m = U.size();
	n = N;
	A = A_;
	B = B_;

	for (int i = 0; i < m; i++) {
		from[i] = U[i];
		to[i] = V[i];

		adj[from[i]].push_back(i);
		adj[to[i]].push_back(i);
	}

	for (int i = 0; i < m; i++)
		fuck.push_back(i);

	mn = get({});
	vector<int> tmp = random_spt();

	fuck = tmp;
	for (int i = 0; i < n; i++) adj[i].clear();
	for (int ind : tmp) {
		adj[from[ind]].push_back(ind);
		adj[to[ind]].push_back(ind);
	}


	int v = find(fucking_root);
	int u = find(v);

	cerr << u << sep << v << endl;

	answer(u, v);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 27776 KB Output is correct
2 Correct 15 ms 27720 KB Output is correct
3 Correct 14 ms 27728 KB Output is correct
4 Correct 15 ms 27728 KB Output is correct
5 Correct 14 ms 27728 KB Output is correct
6 Correct 18 ms 27728 KB Output is correct
7 Correct 15 ms 27632 KB Output is correct
8 Correct 15 ms 27716 KB Output is correct
9 Correct 14 ms 27676 KB Output is correct
10 Correct 14 ms 27620 KB Output is correct
11 Correct 17 ms 27672 KB Output is correct
12 Correct 13 ms 27676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 27728 KB Output is correct
2 Correct 22 ms 28480 KB Output is correct
3 Correct 131 ms 35136 KB Output is correct
4 Correct 130 ms 35028 KB Output is correct
5 Correct 163 ms 35060 KB Output is correct
6 Correct 134 ms 35092 KB Output is correct
7 Correct 117 ms 35148 KB Output is correct
8 Correct 104 ms 35108 KB Output is correct
9 Correct 138 ms 35092 KB Output is correct
10 Correct 148 ms 35136 KB Output is correct
11 Correct 120 ms 36956 KB Output is correct
12 Correct 133 ms 38180 KB Output is correct
13 Correct 132 ms 37076 KB Output is correct
14 Correct 132 ms 37224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 29340 KB Output is correct
2 Correct 37 ms 30824 KB Output is correct
3 Correct 43 ms 30104 KB Output is correct
4 Correct 129 ms 39664 KB Output is correct
5 Correct 106 ms 39776 KB Output is correct
6 Correct 137 ms 41492 KB Output is correct
7 Correct 109 ms 34028 KB Output is correct
8 Correct 93 ms 40732 KB Output is correct
9 Correct 104 ms 43456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 27732 KB Output is correct
2 Correct 25 ms 28484 KB Output is correct
3 Correct 89 ms 33444 KB Output is correct
4 Correct 109 ms 34224 KB Output is correct
5 Correct 104 ms 34700 KB Output is correct
6 Correct 113 ms 33808 KB Output is correct
7 Correct 145 ms 34512 KB Output is correct
8 Correct 124 ms 34352 KB Output is correct
9 Correct 126 ms 35076 KB Output is correct
10 Correct 123 ms 35040 KB Output is correct
11 Correct 154 ms 36432 KB Output is correct
12 Correct 154 ms 38036 KB Output is correct
13 Correct 147 ms 37256 KB Output is correct
14 Correct 142 ms 37956 KB Output is correct
15 Correct 137 ms 34964 KB Output is correct
16 Correct 127 ms 34468 KB Output is correct
17 Correct 158 ms 36332 KB Output is correct
18 Correct 98 ms 35516 KB Output is correct
19 Correct 83 ms 33652 KB Output is correct
20 Correct 117 ms 34204 KB Output is correct
21 Correct 130 ms 35080 KB Output is correct
22 Correct 101 ms 34556 KB Output is correct
23 Correct 93 ms 35432 KB Output is correct
24 Correct 110 ms 36256 KB Output is correct
25 Correct 155 ms 42512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 28496 KB Output is correct
2 Correct 28 ms 28764 KB Output is correct
3 Correct 139 ms 35520 KB Output is correct
4 Correct 138 ms 35724 KB Output is correct
5 Correct 168 ms 36780 KB Output is correct
6 Correct 208 ms 36336 KB Output is correct
7 Correct 161 ms 36720 KB Output is correct
8 Correct 162 ms 36788 KB Output is correct
9 Correct 139 ms 33764 KB Output is correct
10 Correct 171 ms 34152 KB Output is correct
11 Correct 126 ms 33856 KB Output is correct
12 Correct 201 ms 36052 KB Output is correct
13 Correct 213 ms 36308 KB Output is correct
14 Correct 244 ms 36364 KB Output is correct
15 Correct 166 ms 36392 KB Output is correct
16 Correct 150 ms 35456 KB Output is correct
17 Correct 146 ms 35288 KB Output is correct
18 Correct 127 ms 35464 KB Output is correct
19 Correct 145 ms 35392 KB Output is correct
20 Correct 110 ms 35028 KB Output is correct
21 Correct 208 ms 36860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 28616 KB Output is correct
2 Correct 25 ms 28640 KB Output is correct
3 Correct 155 ms 35328 KB Output is correct
4 Partially correct 148 ms 35524 KB Output is partially correct
5 Correct 140 ms 35620 KB Output is correct
6 Partially correct 198 ms 36820 KB Output is partially correct
7 Correct 194 ms 35388 KB Output is correct
8 Partially correct 133 ms 35704 KB Output is partially correct
9 Partially correct 185 ms 35772 KB Output is partially correct
10 Correct 194 ms 37088 KB Output is correct
11 Correct 162 ms 36996 KB Output is correct
12 Correct 152 ms 36876 KB Output is correct
13 Correct 154 ms 34072 KB Output is correct
14 Correct 114 ms 34420 KB Output is correct
15 Correct 174 ms 34368 KB Output is correct
16 Correct 171 ms 34452 KB Output is correct
17 Correct 129 ms 33980 KB Output is correct
18 Correct 118 ms 34452 KB Output is correct
19 Correct 182 ms 35964 KB Output is correct
20 Correct 198 ms 36356 KB Output is correct
21 Correct 187 ms 36776 KB Output is correct
22 Correct 192 ms 36280 KB Output is correct
23 Partially correct 201 ms 36716 KB Output is partially correct
24 Partially correct 167 ms 36368 KB Output is partially correct
25 Correct 218 ms 35888 KB Output is correct
26 Correct 183 ms 36468 KB Output is correct
27 Correct 145 ms 35244 KB Output is correct
28 Correct 143 ms 35244 KB Output is correct
29 Correct 130 ms 35300 KB Output is correct
30 Partially correct 106 ms 35564 KB Output is partially correct
31 Correct 110 ms 35244 KB Output is correct
32 Correct 120 ms 35000 KB Output is correct
33 Correct 115 ms 35428 KB Output is correct
34 Correct 105 ms 35352 KB Output is correct
35 Correct 126 ms 35420 KB Output is correct
36 Correct 147 ms 35148 KB Output is correct
37 Correct 146 ms 35044 KB Output is correct
38 Partially correct 115 ms 35996 KB Output is partially correct
39 Partially correct 187 ms 37388 KB Output is partially correct
40 Correct 152 ms 37552 KB Output is correct
41 Partially correct 199 ms 36812 KB Output is partially correct
42 Correct 178 ms 36792 KB Output is correct