답안 #295397

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
295397 2020-09-09T16:20:38 Z SeDunion 통행료 (IOI18_highway) C++17
100 / 100
522 ms 13516 KB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int M;
const int MAXN = 2e5;
vector<pair<int,int>> g[MAXN];
vector<int> h[2],W;

ll dist;
// map<int,int> id[MAXN];

int find(vector<int>v) {
	int l = 0, r = v.size()-1;
	while (l <= r) {
		int m = (l + r) >> 1;
		for (int i = 0 ; i < M ; ++ i) {
			W[i] = 0;
		}
		for (int i = m ; i < v.size() ; ++ i) {
			for (auto [to,qaz] : g[v[i]]) {
				W[qaz] = 1;
				// W[id[V[i]][to]] = 1;
			}
		}
		if (ask(W)!=dist)l=m+1;
		else r=m-1;
	}
	return v[l-1];
}

void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
	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});
		// id[U[i]][V[i]]=id[V[i]][U[i]]=i;
	}
	W = vector<int>(M,0);
	dist = ask(W);
	int l = 0, r = M - 1;
	while (l <= r) {
		int m = (l + r) >> 1;
		for (int i = 0 ; i < M ; ++ i) {
			W[i] = i <= m;
		}
		if (ask(W) == dist) {
			l = m + 1;
		} else {
			r = m - 1;
		}
	}
	int u = U[l], v = V[l];
																	// cout<<u<<" <-> "<<v<<'\n';
	queue<pair<int,int>>q;
	vector<int>d(N,MAXN);
	q.push({u,0});
	q.push({v,1});
	d[u]=d[v]=0;
	while(q.size()) {
		int v, t;
		tie (v, t) = q.front(); q.pop();
		h[t].push_back (v);
		for (auto [to, i] : g[v]) if (d[to] > d[v] + 1) {
			d[to] = d[v] + 1;
			q.push({to,t});
		}
	}
														// cout<<find(h[0])<<" >-< " << find(h[1]) << "\n";
	answer (find(h[0]),find(h[1]));
}

Compilation message

highway.cpp: In function 'int find(std::vector<int>)':
highway.cpp:21:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |   for (int i = m ; i < v.size() ; ++ i) {
      |                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Correct 4 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 5120 KB Output is correct
6 Correct 5 ms 4992 KB Output is correct
7 Correct 4 ms 4992 KB Output is correct
8 Correct 4 ms 4992 KB Output is correct
9 Correct 3 ms 4992 KB Output is correct
10 Correct 4 ms 4992 KB Output is correct
11 Correct 4 ms 4992 KB Output is correct
12 Correct 6 ms 4992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5128 KB Output is correct
2 Correct 20 ms 5760 KB Output is correct
3 Correct 237 ms 11488 KB Output is correct
4 Correct 216 ms 11528 KB Output is correct
5 Correct 230 ms 11596 KB Output is correct
6 Correct 168 ms 11580 KB Output is correct
7 Correct 237 ms 11600 KB Output is correct
8 Correct 301 ms 11684 KB Output is correct
9 Correct 310 ms 11504 KB Output is correct
10 Correct 214 ms 11488 KB Output is correct
11 Correct 316 ms 10868 KB Output is correct
12 Correct 298 ms 11008 KB Output is correct
13 Correct 271 ms 10860 KB Output is correct
14 Correct 268 ms 10980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 5624 KB Output is correct
2 Correct 33 ms 6264 KB Output is correct
3 Correct 61 ms 6976 KB Output is correct
4 Correct 163 ms 10920 KB Output is correct
5 Correct 170 ms 10836 KB Output is correct
6 Correct 130 ms 10892 KB Output is correct
7 Correct 182 ms 10940 KB Output is correct
8 Correct 156 ms 11004 KB Output is correct
9 Correct 182 ms 10772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 21 ms 5760 KB Output is correct
3 Correct 216 ms 10180 KB Output is correct
4 Correct 328 ms 11552 KB Output is correct
5 Correct 331 ms 11472 KB Output is correct
6 Correct 335 ms 11592 KB Output is correct
7 Correct 298 ms 11508 KB Output is correct
8 Correct 343 ms 11572 KB Output is correct
9 Correct 261 ms 11432 KB Output is correct
10 Correct 288 ms 11676 KB Output is correct
11 Correct 259 ms 10888 KB Output is correct
12 Correct 219 ms 11008 KB Output is correct
13 Correct 310 ms 10800 KB Output is correct
14 Correct 339 ms 10736 KB Output is correct
15 Correct 304 ms 11548 KB Output is correct
16 Correct 328 ms 11512 KB Output is correct
17 Correct 288 ms 11032 KB Output is correct
18 Correct 259 ms 10984 KB Output is correct
19 Correct 304 ms 11616 KB Output is correct
20 Correct 325 ms 10964 KB Output is correct
21 Correct 139 ms 12512 KB Output is correct
22 Correct 145 ms 12264 KB Output is correct
23 Correct 177 ms 11732 KB Output is correct
24 Correct 167 ms 11652 KB Output is correct
25 Correct 204 ms 11052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 5760 KB Output is correct
2 Correct 24 ms 5800 KB Output is correct
3 Correct 263 ms 12012 KB Output is correct
4 Correct 303 ms 12328 KB Output is correct
5 Correct 436 ms 13516 KB Output is correct
6 Correct 485 ms 13240 KB Output is correct
7 Correct 434 ms 13272 KB Output is correct
8 Correct 331 ms 13220 KB Output is correct
9 Correct 239 ms 11276 KB Output is correct
10 Correct 230 ms 11588 KB Output is correct
11 Correct 185 ms 11968 KB Output is correct
12 Correct 359 ms 12884 KB Output is correct
13 Correct 445 ms 13180 KB Output is correct
14 Correct 415 ms 13428 KB Output is correct
15 Correct 490 ms 13192 KB Output is correct
16 Correct 301 ms 12120 KB Output is correct
17 Correct 247 ms 12140 KB Output is correct
18 Correct 251 ms 12348 KB Output is correct
19 Correct 202 ms 12136 KB Output is correct
20 Correct 300 ms 12180 KB Output is correct
21 Correct 410 ms 13328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 5760 KB Output is correct
2 Correct 19 ms 5760 KB Output is correct
3 Correct 363 ms 12076 KB Output is correct
4 Correct 357 ms 12140 KB Output is correct
5 Correct 367 ms 12400 KB Output is correct
6 Correct 384 ms 13224 KB Output is correct
7 Correct 320 ms 11856 KB Output is correct
8 Correct 376 ms 12036 KB Output is correct
9 Correct 430 ms 12268 KB Output is correct
10 Correct 491 ms 13408 KB Output is correct
11 Correct 425 ms 13268 KB Output is correct
12 Correct 422 ms 13376 KB Output is correct
13 Correct 230 ms 11960 KB Output is correct
14 Correct 214 ms 11640 KB Output is correct
15 Correct 212 ms 12004 KB Output is correct
16 Correct 228 ms 11552 KB Output is correct
17 Correct 281 ms 11952 KB Output is correct
18 Correct 248 ms 11636 KB Output is correct
19 Correct 459 ms 12812 KB Output is correct
20 Correct 425 ms 13084 KB Output is correct
21 Correct 522 ms 13436 KB Output is correct
22 Correct 484 ms 13388 KB Output is correct
23 Correct 432 ms 13260 KB Output is correct
24 Correct 383 ms 13196 KB Output is correct
25 Correct 420 ms 13256 KB Output is correct
26 Correct 405 ms 13332 KB Output is correct
27 Correct 200 ms 12216 KB Output is correct
28 Correct 250 ms 12168 KB Output is correct
29 Correct 275 ms 12488 KB Output is correct
30 Correct 173 ms 12036 KB Output is correct
31 Correct 225 ms 12284 KB Output is correct
32 Correct 228 ms 12072 KB Output is correct
33 Correct 179 ms 12432 KB Output is correct
34 Correct 258 ms 12116 KB Output is correct
35 Correct 237 ms 12168 KB Output is correct
36 Correct 262 ms 12008 KB Output is correct
37 Correct 265 ms 12428 KB Output is correct
38 Correct 158 ms 12132 KB Output is correct
39 Correct 384 ms 13268 KB Output is correct
40 Correct 391 ms 13320 KB Output is correct
41 Correct 238 ms 13288 KB Output is correct
42 Correct 414 ms 13188 KB Output is correct