Submission #594827

# Submission time Handle Problem Language Result Execution time Memory
594827 2022-07-13T02:49:23 Z Temmie Highway Tolls (IOI18_highway) C++17
100 / 100
256 ms 9564 KB
#include "highway.h"
#include <bits/stdc++.h>

int n, m;
std::vector <std::vector <int>> g;

long long dist;

void find_pair(int _n, std::vector <int> _u, std::vector <int> _v, int a, int b) {
	n = _n;
	m = _u.size();
	g.resize(n);
	for (int i = 0; i < m; i++) {
		g[_u[i]].push_back(i);
		g[_v[i]].push_back(i);
	}
	dist = ask(std::vector <int> (m, 0)) / a;
	int root[2] = { -1, -1 };
	int sec = -1;
	{
		int l = 0, r = m - 1, best = 0;
		while (l <= r) {
			int mid = (l + r) >> 1;
			std::vector <int> cur(m, 1);
			for (int i = 0; i <= mid; i++) {
				cur[i] = 0;
			}
			long long val = ask(cur);
			if (val != dist * a) {
				best = mid + 1;
				l = mid + 1;
			} else {
				r = mid - 1;
			}
		}
		root[0] = _u[best];
		root[1] = _v[best];
		sec = best;
	}
	assert(root[0] != -1 && root[1] != -1);
	assert(sec != -1);
	std::vector <int> nod[2];
	std::vector <int> par(n, -1);
	{
		std::queue <int> q;
		q.push(root[0]);
		q.push(root[1]);
		std::vector <bool> vis(n, false);
		std::vector <int> rof(n, -1);
		rof[root[0]] = root[0];
		rof[root[1]] = root[1];
		nod[0].push_back(root[0]);
		nod[1].push_back(root[1]);
		vis[root[0]] = vis[root[1]] = true;
		par[root[0]] = par[root[1]] = sec;
		while (q.size()) {
			int v = q.front(); q.pop();
			for (int x : g[v]) {
				int to = v ^ _u[x] ^ _v[x];
				if (vis[to]) {
					continue;
				}
				vis[to] = true;
				rof[to] = rof[v];
				nod[rof[v] == root[0] ? 0 : 1].push_back(to);
				q.push(to);
				par[to] = x;
			}
		}
	}
	int ans[2];
	for (int i = 0; i <= 1; i++) {
		int l = 0, r = (int) nod[i].size() - 1, best = nod[i][0];
		while (l < r) {
			int mid = (l + r) >> 1;
			std::vector <int> cur(m, 1);
			for (int x : nod[i ^ 1]) {
				cur[par[x]] = 0;
			}
			for (int j = 0; j <= mid; j++) {
				cur[par[nod[i][j]]] = 0;
			}
			long long val = ask(cur);
			if (val > dist * a) {
				best = nod[i][mid + 1];
				l = mid + 1;
			} else {
				r = mid;
			}
		}
		ans[i] = best;
	}
	answer(ans[0], ans[1]);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 11 ms 1136 KB Output is correct
3 Correct 175 ms 8332 KB Output is correct
4 Correct 178 ms 8448 KB Output is correct
5 Correct 154 ms 8324 KB Output is correct
6 Correct 125 ms 8336 KB Output is correct
7 Correct 109 ms 8336 KB Output is correct
8 Correct 127 ms 8408 KB Output is correct
9 Correct 122 ms 8292 KB Output is correct
10 Correct 160 ms 8488 KB Output is correct
11 Correct 145 ms 8028 KB Output is correct
12 Correct 167 ms 8260 KB Output is correct
13 Correct 164 ms 8236 KB Output is correct
14 Correct 140 ms 8232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1208 KB Output is correct
2 Correct 21 ms 2008 KB Output is correct
3 Correct 34 ms 2904 KB Output is correct
4 Correct 136 ms 8068 KB Output is correct
5 Correct 98 ms 8072 KB Output is correct
6 Correct 132 ms 8456 KB Output is correct
7 Correct 120 ms 8240 KB Output is correct
8 Correct 137 ms 8060 KB Output is correct
9 Correct 106 ms 8232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 12 ms 1136 KB Output is correct
3 Correct 107 ms 6556 KB Output is correct
4 Correct 155 ms 8336 KB Output is correct
5 Correct 112 ms 8336 KB Output is correct
6 Correct 102 ms 8340 KB Output is correct
7 Correct 94 ms 8324 KB Output is correct
8 Correct 108 ms 8320 KB Output is correct
9 Correct 155 ms 8076 KB Output is correct
10 Correct 125 ms 8324 KB Output is correct
11 Correct 180 ms 8232 KB Output is correct
12 Correct 179 ms 8200 KB Output is correct
13 Correct 186 ms 7924 KB Output is correct
14 Correct 184 ms 7932 KB Output is correct
15 Correct 104 ms 8336 KB Output is correct
16 Correct 142 ms 8336 KB Output is correct
17 Correct 146 ms 8232 KB Output is correct
18 Correct 176 ms 8232 KB Output is correct
19 Correct 95 ms 8416 KB Output is correct
20 Correct 149 ms 8368 KB Output is correct
21 Correct 99 ms 8604 KB Output is correct
22 Correct 92 ms 8592 KB Output is correct
23 Correct 125 ms 8476 KB Output is correct
24 Correct 169 ms 8512 KB Output is correct
25 Correct 139 ms 8312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1220 KB Output is correct
2 Correct 16 ms 1276 KB Output is correct
3 Correct 155 ms 8784 KB Output is correct
4 Correct 137 ms 8736 KB Output is correct
5 Correct 207 ms 9492 KB Output is correct
6 Correct 167 ms 9280 KB Output is correct
7 Correct 212 ms 9288 KB Output is correct
8 Correct 234 ms 9344 KB Output is correct
9 Correct 122 ms 5712 KB Output is correct
10 Correct 128 ms 5940 KB Output is correct
11 Correct 188 ms 6524 KB Output is correct
12 Correct 159 ms 8508 KB Output is correct
13 Correct 237 ms 8780 KB Output is correct
14 Correct 182 ms 9292 KB Output is correct
15 Correct 178 ms 9140 KB Output is correct
16 Correct 150 ms 6836 KB Output is correct
17 Correct 151 ms 8696 KB Output is correct
18 Correct 126 ms 8748 KB Output is correct
19 Correct 114 ms 8712 KB Output is correct
20 Correct 127 ms 8792 KB Output is correct
21 Correct 185 ms 9192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1232 KB Output is correct
2 Correct 14 ms 1232 KB Output is correct
3 Correct 133 ms 8536 KB Output is correct
4 Correct 154 ms 8856 KB Output is correct
5 Correct 160 ms 8796 KB Output is correct
6 Correct 177 ms 9344 KB Output is correct
7 Correct 142 ms 8592 KB Output is correct
8 Correct 166 ms 9080 KB Output is correct
9 Correct 170 ms 8728 KB Output is correct
10 Correct 174 ms 9296 KB Output is correct
11 Correct 253 ms 9564 KB Output is correct
12 Correct 204 ms 9332 KB Output is correct
13 Correct 130 ms 6548 KB Output is correct
14 Correct 119 ms 6060 KB Output is correct
15 Correct 121 ms 6536 KB Output is correct
16 Correct 188 ms 5980 KB Output is correct
17 Correct 128 ms 6588 KB Output is correct
18 Correct 126 ms 5952 KB Output is correct
19 Correct 183 ms 8592 KB Output is correct
20 Correct 168 ms 8756 KB Output is correct
21 Correct 173 ms 9136 KB Output is correct
22 Correct 189 ms 9440 KB Output is correct
23 Correct 182 ms 9380 KB Output is correct
24 Correct 202 ms 9200 KB Output is correct
25 Correct 172 ms 9404 KB Output is correct
26 Correct 195 ms 9540 KB Output is correct
27 Correct 145 ms 8824 KB Output is correct
28 Correct 109 ms 8672 KB Output is correct
29 Correct 116 ms 8820 KB Output is correct
30 Correct 145 ms 8728 KB Output is correct
31 Correct 144 ms 8728 KB Output is correct
32 Correct 127 ms 8652 KB Output is correct
33 Correct 128 ms 8924 KB Output is correct
34 Correct 173 ms 8804 KB Output is correct
35 Correct 131 ms 8808 KB Output is correct
36 Correct 182 ms 8624 KB Output is correct
37 Correct 120 ms 8840 KB Output is correct
38 Correct 119 ms 8828 KB Output is correct
39 Correct 188 ms 9296 KB Output is correct
40 Correct 172 ms 9296 KB Output is correct
41 Correct 256 ms 9264 KB Output is correct
42 Correct 231 ms 9448 KB Output is correct