Submission #162957

# Submission time Handle Problem Language Result Execution time Memory
162957 2019-11-10T12:04:55 Z Minnakhmetov Highway Tolls (IOI18_highway) C++14
100 / 100
366 ms 14532 KB
#include "highway.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

struct E {
	int to, i;
};

const int N = 2e5 + 5;
vector<E> g[N];
int anc[N], d[N], pr[N], h[N];

void find_pair(int n, vector<int> u, vector<int> v, int a, int b) {
	int m = u.size();

	for (int i = 0; i < m; i++) {
		g[u[i]].push_back({v[i], i});
		g[v[i]].push_back({u[i], i});
		pr[i] = rand();
	}

	ll dist = ask(vector<int>(m, 0)) / a;

	int l = -1, r = m - 1;
	while (r - l > 1) {
		int p = (l + r) >> 1;
		vector<int> w(m, 0);
		fill(w.begin(), w.begin() + p + 1, 1);
		if (ask(w) != dist * a)
			r = p;
		else
			l = p;
	}

	int rt[2] = {u[r], v[r]},
		mid = r;

	// cout << rt[0] << " " << rt[1] << "\n";

	queue<int> q;
	fill(d, d + n, -1);
	d[rt[0]] = d[rt[1]] = 0;
	h[rt[1]] = 1;
	q.push(rt[0]);
	q.push(rt[1]);

	vector<int> half[2];

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

		for (E e : g[node]) {
			if (d[e.to] == -1) {
				d[e.to] = d[node] + 1;
				h[e.to] = h[node];
				anc[e.to] = e.i;
				half[h[node]].push_back(e.i);
				q.push(e.to);
			}
		}
	}

	for (int i = 0; i < m; i++) {
		if (d[u[i]] > d[v[i]])
			swap(u[i], v[i]);
	}


	for (int i = 0; i < 2; i++) {
		sort(all(half[i]), [&](int x, int y) {
			return d[v[x]] > d[v[y]];
		});
	}

	// for (int i = 0; i < 2; i++) {
	// 	for (int j : half[i]) {
	// 		cout << u[j] << " " << v[j] << "\n";
	// 	}
	// 	cout << "\n";
	// }

	int ans[2];

	for (int i = 0; i < 2; i++) {
		int l = -1, r = half[i].size();

		while (r - l > 1) {
			int p = (l + r) >> 1;
			vector<int> w(m, 1);

			w[mid] = 0;

			for (int j : half[i ^ 1])
				w[j] = 0;
			for (int j = p + 1; j < half[i].size(); j++) {
				w[half[i][j]] = 0;
			}

			if (ask(w) != dist * a)
				r = p;
			else
				l = p;
		}

		if (r == half[i].size())
			ans[i] = rt[i];
		else
			ans[i] = v[half[i][r]];
	}

	// cout << ans[0] << " " << ans[1] << "\n";

	answer(ans[0], ans[1]);
}

Compilation message

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:100:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int j = p + 1; j < half[i].size(); j++) {
                        ~~^~~~~~~~~~~~~~~~
highway.cpp:110:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (r == half[i].size())
       ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5012 KB Output is correct
2 Correct 6 ms 4984 KB Output is correct
3 Correct 6 ms 4984 KB Output is correct
4 Correct 6 ms 4984 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 6 ms 4984 KB Output is correct
7 Correct 6 ms 5024 KB Output is correct
8 Correct 6 ms 4984 KB Output is correct
9 Correct 6 ms 4984 KB Output is correct
10 Correct 6 ms 5032 KB Output is correct
11 Correct 6 ms 5032 KB Output is correct
12 Correct 7 ms 5032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5112 KB Output is correct
2 Correct 27 ms 5756 KB Output is correct
3 Correct 220 ms 12156 KB Output is correct
4 Correct 235 ms 12168 KB Output is correct
5 Correct 229 ms 12112 KB Output is correct
6 Correct 267 ms 12124 KB Output is correct
7 Correct 218 ms 12156 KB Output is correct
8 Correct 218 ms 12224 KB Output is correct
9 Correct 211 ms 12220 KB Output is correct
10 Correct 225 ms 12176 KB Output is correct
11 Correct 231 ms 11792 KB Output is correct
12 Correct 230 ms 11592 KB Output is correct
13 Correct 237 ms 11572 KB Output is correct
14 Correct 251 ms 11576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 5752 KB Output is correct
2 Correct 42 ms 6548 KB Output is correct
3 Correct 83 ms 7280 KB Output is correct
4 Correct 175 ms 11752 KB Output is correct
5 Correct 187 ms 11768 KB Output is correct
6 Correct 185 ms 11780 KB Output is correct
7 Correct 186 ms 11632 KB Output is correct
8 Correct 176 ms 11632 KB Output is correct
9 Correct 188 ms 11648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5112 KB Output is correct
2 Correct 29 ms 5884 KB Output is correct
3 Correct 151 ms 10668 KB Output is correct
4 Correct 213 ms 12144 KB Output is correct
5 Correct 211 ms 12116 KB Output is correct
6 Correct 197 ms 12260 KB Output is correct
7 Correct 208 ms 12156 KB Output is correct
8 Correct 212 ms 12160 KB Output is correct
9 Correct 221 ms 12156 KB Output is correct
10 Correct 216 ms 12120 KB Output is correct
11 Correct 226 ms 11600 KB Output is correct
12 Correct 252 ms 11672 KB Output is correct
13 Correct 236 ms 11824 KB Output is correct
14 Correct 240 ms 11688 KB Output is correct
15 Correct 203 ms 12108 KB Output is correct
16 Correct 221 ms 12116 KB Output is correct
17 Correct 226 ms 11636 KB Output is correct
18 Correct 207 ms 11576 KB Output is correct
19 Correct 239 ms 12100 KB Output is correct
20 Correct 224 ms 11568 KB Output is correct
21 Correct 187 ms 12748 KB Output is correct
22 Correct 193 ms 12700 KB Output is correct
23 Correct 210 ms 12512 KB Output is correct
24 Correct 216 ms 12496 KB Output is correct
25 Correct 222 ms 11828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 5864 KB Output is correct
2 Correct 35 ms 5880 KB Output is correct
3 Correct 255 ms 12568 KB Output is correct
4 Correct 288 ms 12960 KB Output is correct
5 Correct 314 ms 14412 KB Output is correct
6 Correct 309 ms 14244 KB Output is correct
7 Correct 324 ms 14264 KB Output is correct
8 Correct 323 ms 14284 KB Output is correct
9 Correct 256 ms 11600 KB Output is correct
10 Correct 255 ms 12060 KB Output is correct
11 Correct 277 ms 12524 KB Output is correct
12 Correct 318 ms 13716 KB Output is correct
13 Correct 331 ms 13956 KB Output is correct
14 Correct 312 ms 14360 KB Output is correct
15 Correct 321 ms 13988 KB Output is correct
16 Correct 288 ms 12736 KB Output is correct
17 Correct 201 ms 12620 KB Output is correct
18 Correct 230 ms 12780 KB Output is correct
19 Correct 224 ms 12604 KB Output is correct
20 Correct 230 ms 12712 KB Output is correct
21 Correct 305 ms 13940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 5880 KB Output is correct
2 Correct 33 ms 5928 KB Output is correct
3 Correct 257 ms 12768 KB Output is correct
4 Correct 255 ms 12944 KB Output is correct
5 Correct 276 ms 13268 KB Output is correct
6 Correct 304 ms 14292 KB Output is correct
7 Correct 223 ms 12572 KB Output is correct
8 Correct 260 ms 12744 KB Output is correct
9 Correct 277 ms 13328 KB Output is correct
10 Correct 320 ms 14528 KB Output is correct
11 Correct 304 ms 14168 KB Output is correct
12 Correct 320 ms 14252 KB Output is correct
13 Correct 246 ms 12548 KB Output is correct
14 Correct 260 ms 12056 KB Output is correct
15 Correct 253 ms 12508 KB Output is correct
16 Correct 257 ms 12148 KB Output is correct
17 Correct 262 ms 12536 KB Output is correct
18 Correct 253 ms 12224 KB Output is correct
19 Correct 366 ms 13888 KB Output is correct
20 Correct 296 ms 13856 KB Output is correct
21 Correct 324 ms 14316 KB Output is correct
22 Correct 324 ms 14360 KB Output is correct
23 Correct 308 ms 14256 KB Output is correct
24 Correct 317 ms 14416 KB Output is correct
25 Correct 326 ms 14532 KB Output is correct
26 Correct 326 ms 14376 KB Output is correct
27 Correct 201 ms 12680 KB Output is correct
28 Correct 236 ms 12576 KB Output is correct
29 Correct 207 ms 12924 KB Output is correct
30 Correct 240 ms 12676 KB Output is correct
31 Correct 210 ms 12732 KB Output is correct
32 Correct 207 ms 12656 KB Output is correct
33 Correct 201 ms 12860 KB Output is correct
34 Correct 230 ms 12660 KB Output is correct
35 Correct 211 ms 12612 KB Output is correct
36 Correct 205 ms 12524 KB Output is correct
37 Correct 212 ms 12864 KB Output is correct
38 Correct 248 ms 12884 KB Output is correct
39 Correct 342 ms 14348 KB Output is correct
40 Correct 321 ms 14128 KB Output is correct
41 Correct 308 ms 14032 KB Output is correct
42 Correct 305 ms 14280 KB Output is correct