Submission #102719

# Submission time Handle Problem Language Result Execution time Memory
102719 2019-03-27T08:26:20 Z bert30702 Highway Tolls (IOI18_highway) C++17
51 / 100
363 ms 63756 KB
#include <bits/stdc++.h>
#include "highway.h"
#define pii pair<int, int>
#define F first
#define S second
#define int long long
using namespace std;
const int MX = 1e6 + 100;
vector<pii> G1[MX], G2[MX];
bitset<MX> pass, edge;
int deep[MX];
//void answer(int a, int b) {
//	cout << "! " << a << ' ' << b;
//}
//int ask(vector<int32_t> v) {
//	for(auto it: v) cout << it << ' '; cout << endl;
//	int val; cin >> val; return val;
//}
vector<pii> que;
void dfs(int u, int l, int d) {
	que.push_back({u, l});
	deep[u] = d;
	for(auto it: G2[u]) {
		dfs(it.F, it.S, d + 1);
	}
}
void find_pair(int32_t n, vector<int32_t> u, vector<int32_t> v, int32_t a, int32_t b) {
	for(int i = 0; i < u.size(); i ++) {
		G1[u[i]].push_back({v[i], i});
		G1[v[i]].push_back({u[i], i});
	}
	int d = ask(vector<int32_t>(u.size(), 0));
	int l = 0, r = u.size() - 1;
	while(l != r) {
		int m = l + r >> 1;
		vector<int32_t> query(u.size(), 0);
		for(int j = l; j <= m; j ++) query[j] = 1;
		if(ask(query) > d) r = m;
		else               l = m + 1;
	}
	pass[u[l]] = pass[v[l]] = edge[l] = true;
	queue<pii> q;
	q.push({u[l], l});
	q.push({v[l], l});
	while(q.size()) {
		pii p = q.front(); q.pop();
		for(auto i: G1[p.F]) {
			if(!pass[i.F]) {
				edge[i.S] = true;
				pass[i.F] = true;
				G2[p.F].push_back(i);
				q.push(i);
			}
		}
	}
	int x = -1, y = -1;
	{
		que.clear();
		dfs(u[l], l, 1);
		sort(que.begin(), que.end(), [](pii a, pii b) {
			return deep[a.F] < deep[b.F];	
		});
		assert(que[0].F == u[l]);
		int l = 0, r = que.size() - 1;
		while(l != r) {
			int m = l + r >> 1;
			vector<int32_t> query(u.size(), 1);
			for(int i = 0; i < u.size(); i ++) {
				if(edge[i]) query[i] = 0;
			}
			for(int i = m + 1; i <= r; i ++) {
				query[que[i].S] = 1;
			}
			if(ask(query) > d) l = m + 1;
			else                   r = m;
		}
		x = que[l].F;
	}
	{
		que.clear();
		dfs(v[l], l, 1);
		sort(que.begin(), que.end(), [](pii a, pii b) {
			return deep[a.F] < deep[b.F];
		});
		assert(que[0].F == v[l]);
		int l = 0, r = que.size() - 1;
		while(l != r) {
			int m = l + r >> 1;
			vector<int32_t> query(u.size(), 1);
			for(int i = 0; i < u.size(); i ++) {
				if(edge[i]) query[i] = 0;
			}
			for(int i = m + 1; i <= r; i ++) {
				query[que[i].S] = 1;
			}
			if(ask(query) > d) l = m + 1;
			else               r = m;
		}
		y = que[l].F;
	}
	answer(x, y);
}
//main () {
//	find_pair(4, {0, 0, 0, 1, 1, 2}, {1, 2, 3, 2, 3, 3}, 1, 2);
//}

Compilation message

highway.cpp: In function 'void find_pair(int32_t, std::vector<int>, std::vector<int>, int32_t, int32_t)':
highway.cpp:28:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < u.size(); i ++) {
                 ~~^~~~~~~~~~
highway.cpp:35:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = l + r >> 1;
           ~~^~~
highway.cpp:66:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    int m = l + r >> 1;
            ~~^~~
highway.cpp:68:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i = 0; i < u.size(); i ++) {
                   ~~^~~~~~~~~~
highway.cpp:88:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    int m = l + r >> 1;
            ~~^~~
highway.cpp:90:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i = 0; i < u.size(); i ++) {
                   ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 46 ms 47304 KB Output is correct
2 Correct 44 ms 47304 KB Output is correct
3 Correct 43 ms 47272 KB Output is correct
4 Correct 44 ms 47268 KB Output is correct
5 Correct 54 ms 47272 KB Output is correct
6 Correct 45 ms 47304 KB Output is correct
7 Correct 44 ms 47420 KB Output is correct
8 Correct 50 ms 47332 KB Output is correct
9 Correct 45 ms 47352 KB Output is correct
10 Correct 44 ms 47224 KB Output is correct
11 Correct 44 ms 47300 KB Output is correct
12 Correct 52 ms 47228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 47380 KB Output is correct
2 Correct 64 ms 48644 KB Output is correct
3 Correct 277 ms 58952 KB Output is correct
4 Correct 278 ms 58864 KB Output is correct
5 Correct 271 ms 58948 KB Output is correct
6 Correct 256 ms 58940 KB Output is correct
7 Correct 266 ms 58872 KB Output is correct
8 Correct 287 ms 58980 KB Output is correct
9 Correct 273 ms 58952 KB Output is correct
10 Correct 268 ms 58868 KB Output is correct
11 Correct 269 ms 59404 KB Output is correct
12 Correct 305 ms 60932 KB Output is correct
13 Correct 327 ms 60724 KB Output is correct
14 Correct 298 ms 60804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 49192 KB Output is correct
2 Correct 85 ms 50680 KB Output is correct
3 Correct 105 ms 52484 KB Output is correct
4 Correct 251 ms 61420 KB Output is correct
5 Correct 230 ms 61416 KB Output is correct
6 Correct 227 ms 63176 KB Output is correct
7 Correct 218 ms 63756 KB Output is correct
8 Correct 217 ms 62024 KB Output is correct
9 Correct 218 ms 63028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 47400 KB Output is correct
2 Correct 63 ms 48516 KB Output is correct
3 Correct 205 ms 56504 KB Output is correct
4 Correct 269 ms 58940 KB Output is correct
5 Correct 251 ms 58944 KB Output is correct
6 Correct 279 ms 58952 KB Output is correct
7 Correct 257 ms 58988 KB Output is correct
8 Correct 248 ms 58940 KB Output is correct
9 Correct 225 ms 58948 KB Output is correct
10 Correct 251 ms 58952 KB Output is correct
11 Correct 281 ms 60424 KB Output is correct
12 Correct 336 ms 60776 KB Output is correct
13 Correct 269 ms 60804 KB Output is correct
14 Correct 259 ms 59772 KB Output is correct
15 Correct 269 ms 58896 KB Output is correct
16 Correct 248 ms 58956 KB Output is correct
17 Correct 284 ms 60536 KB Output is correct
18 Correct 278 ms 60952 KB Output is correct
19 Correct 259 ms 58896 KB Output is correct
20 Correct 310 ms 61020 KB Output is correct
21 Correct 215 ms 58940 KB Output is correct
22 Correct 210 ms 59056 KB Output is correct
23 Correct 238 ms 57136 KB Output is correct
24 Correct 233 ms 57544 KB Output is correct
25 Correct 273 ms 63328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 48552 KB Output is correct
2 Correct 72 ms 48788 KB Output is correct
3 Correct 309 ms 59632 KB Output is correct
4 Correct 347 ms 60140 KB Output is correct
5 Correct 359 ms 60448 KB Output is correct
6 Incorrect 363 ms 61404 KB Output is incorrect: {s, t} is wrong.
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 67 ms 48528 KB Output is correct
2 Correct 73 ms 48788 KB Output is correct
3 Correct 284 ms 58616 KB Output is correct
4 Incorrect 308 ms 59392 KB Output is incorrect: {s, t} is wrong.
5 Halted 0 ms 0 KB -