Submission #799446

# Submission time Handle Problem Language Result Execution time Memory
799446 2023-07-31T14:35:51 Z Sohsoh84 Highway Tolls (IOI18_highway) C++17
90 / 100
234 ms 42040 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);

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

	for (int ind : adj[v]) {
		int u = f(ind, v);
		if (u == p) continue;
		if (bad[u]) continue;

		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);

	jahel.insert(jahel.begin(), 0);

	tof = 0;
	int l = 1, r = int(dfs_order.size()) - 1;
	if (tof) r = int(jahel.size()) - 1;

	while (l < r) {
		int mid = (l + r) >> 1;
		int tmid = mid;
		if (tof) {
			tmid = 0;
			while (dfs_order[tmid] != jahel[mid]) tmid++;
		}

		if (getp(1, tmid) == mn) r = mid;
		else l = mid + 1;
	}

	return (tof ? jahel[l] : dfs_order[l]);

}

int dist[MAXN];

const double Z = 0.45;

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, 1);

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

	answer(u, v);
}

# Verdict Execution time Memory Grader output
1 Correct 14 ms 27708 KB Output is correct
2 Correct 14 ms 27696 KB Output is correct
3 Correct 14 ms 27728 KB Output is correct
4 Correct 14 ms 27728 KB Output is correct
5 Correct 14 ms 27724 KB Output is correct
6 Correct 14 ms 27724 KB Output is correct
7 Correct 15 ms 27760 KB Output is correct
8 Correct 14 ms 27696 KB Output is correct
9 Correct 14 ms 27728 KB Output is correct
10 Correct 14 ms 27720 KB Output is correct
11 Correct 14 ms 27728 KB Output is correct
12 Correct 14 ms 27748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 27760 KB Output is correct
2 Correct 20 ms 28452 KB Output is correct
3 Correct 109 ms 35268 KB Output is correct
4 Correct 130 ms 35060 KB Output is correct
5 Correct 106 ms 35284 KB Output is correct
6 Correct 110 ms 35096 KB Output is correct
7 Correct 130 ms 35128 KB Output is correct
8 Correct 146 ms 35016 KB Output is correct
9 Correct 114 ms 35136 KB Output is correct
10 Correct 136 ms 35228 KB Output is correct
11 Correct 114 ms 36624 KB Output is correct
12 Correct 129 ms 37544 KB Output is correct
13 Correct 141 ms 36756 KB Output is correct
14 Correct 151 ms 36964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 29128 KB Output is correct
2 Correct 36 ms 30572 KB Output is correct
3 Correct 36 ms 30040 KB Output is correct
4 Correct 81 ms 38804 KB Output is correct
5 Correct 95 ms 38884 KB Output is correct
6 Correct 129 ms 40360 KB Output is correct
7 Correct 73 ms 33956 KB Output is correct
8 Correct 119 ms 39708 KB Output is correct
9 Correct 105 ms 42040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 27732 KB Output is correct
2 Correct 28 ms 28580 KB Output is correct
3 Correct 105 ms 33392 KB Output is correct
4 Correct 112 ms 34236 KB Output is correct
5 Correct 123 ms 34700 KB Output is correct
6 Correct 84 ms 33808 KB Output is correct
7 Correct 94 ms 34512 KB Output is correct
8 Correct 134 ms 34364 KB Output is correct
9 Correct 116 ms 35072 KB Output is correct
10 Correct 126 ms 35096 KB Output is correct
11 Correct 121 ms 36176 KB Output is correct
12 Correct 154 ms 37540 KB Output is correct
13 Correct 131 ms 36896 KB Output is correct
14 Correct 125 ms 37380 KB Output is correct
15 Correct 149 ms 34964 KB Output is correct
16 Correct 100 ms 34204 KB Output is correct
17 Correct 146 ms 36076 KB Output is correct
18 Correct 110 ms 35316 KB Output is correct
19 Correct 99 ms 33640 KB Output is correct
20 Correct 94 ms 34140 KB Output is correct
21 Correct 98 ms 35056 KB Output is correct
22 Correct 116 ms 34840 KB Output is correct
23 Correct 95 ms 35680 KB Output is correct
24 Correct 107 ms 36456 KB Output is correct
25 Correct 156 ms 41292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 28596 KB Output is correct
2 Correct 28 ms 28744 KB Output is correct
3 Correct 149 ms 35416 KB Output is correct
4 Correct 183 ms 35640 KB Output is correct
5 Correct 234 ms 36804 KB Output is correct
6 Correct 190 ms 36396 KB Output is correct
7 Correct 184 ms 37200 KB Output is correct
8 Correct 156 ms 36824 KB Output is correct
9 Correct 117 ms 33696 KB Output is correct
10 Correct 179 ms 34168 KB Output is correct
11 Correct 190 ms 33924 KB Output is correct
12 Correct 146 ms 36068 KB Output is correct
13 Correct 141 ms 36304 KB Output is correct
14 Correct 192 ms 36464 KB Output is correct
15 Correct 175 ms 36396 KB Output is correct
16 Correct 157 ms 35348 KB Output is correct
17 Correct 138 ms 35596 KB Output is correct
18 Correct 133 ms 35424 KB Output is correct
19 Correct 129 ms 35700 KB Output is correct
20 Correct 110 ms 35284 KB Output is correct
21 Correct 189 ms 36796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 28608 KB Output is correct
2 Correct 30 ms 28604 KB Output is correct
3 Correct 155 ms 35496 KB Output is correct
4 Partially correct 170 ms 35500 KB Output is partially correct
5 Correct 181 ms 35612 KB Output is correct
6 Partially correct 208 ms 37048 KB Output is partially correct
7 Correct 158 ms 35432 KB Output is correct
8 Partially correct 142 ms 35708 KB Output is partially correct
9 Correct 164 ms 35776 KB Output is correct
10 Correct 181 ms 36964 KB Output is correct
11 Correct 177 ms 36992 KB Output is correct
12 Correct 216 ms 36944 KB Output is correct
13 Correct 175 ms 34080 KB Output is correct
14 Correct 149 ms 34324 KB Output is correct
15 Correct 164 ms 34460 KB Output is correct
16 Correct 137 ms 34472 KB Output is correct
17 Correct 143 ms 34016 KB Output is correct
18 Correct 143 ms 34604 KB Output is correct
19 Correct 184 ms 36096 KB Output is correct
20 Correct 152 ms 36332 KB Output is correct
21 Correct 172 ms 36632 KB Output is correct
22 Partially correct 179 ms 36288 KB Output is partially correct
23 Correct 199 ms 36680 KB Output is correct
24 Correct 200 ms 36432 KB Output is correct
25 Correct 173 ms 35884 KB Output is correct
26 Correct 182 ms 36512 KB Output is correct
27 Correct 143 ms 35268 KB Output is correct
28 Correct 144 ms 35416 KB Output is correct
29 Correct 153 ms 35372 KB Output is correct
30 Correct 125 ms 35612 KB Output is correct
31 Correct 121 ms 35332 KB Output is correct
32 Correct 108 ms 35040 KB Output is correct
33 Correct 110 ms 35416 KB Output is correct
34 Correct 100 ms 35864 KB Output is correct
35 Correct 106 ms 35800 KB Output is correct
36 Correct 121 ms 35164 KB Output is correct
37 Correct 127 ms 35292 KB Output is correct
38 Correct 164 ms 35948 KB Output is correct
39 Partially correct 163 ms 37236 KB Output is partially correct
40 Correct 212 ms 37388 KB Output is correct
41 Correct 201 ms 36820 KB Output is correct
42 Correct 183 ms 36700 KB Output is correct