답안 #77105

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
77105 2018-09-21T12:06:09 Z gs14004 통행료 (IOI18_highway) C++17
100 / 100
341 ms 9968 KB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 90005;

int dist[MAXN];
vector<int> gph[MAXN];

lint cut_ask(int m, vector<int> &c, vector<int> &u, vector<int> &v){
	bitset<MAXN> vis;
	for(auto &i : c) vis[i] = 1;
	vector<int> query(m);
	for(int i=0; i<m; i++) if(vis[u[i]] != vis[v[i]]) query[i] = 1;
	return ask(query);
}

void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
	int M = U.size();
	for(int i=0; i<M; i++){
		gph[U[i]].emplace_back(V[i]);
		gph[V[i]].emplace_back(U[i]); 
	}
	vector<int> v(M);
	lint stdist = ask(v) / A;
	int s = 0, e = M - 1;
	while(s != e){
		int m = (s + e) / 2;
		fill(v.begin() + m + 1, v.end(), 0);
		fill(v.begin(), v.begin() + m + 1, 1);
		if(ask(v) != A * stdist) e = m;
		else s = m + 1;
	}
	vector<int> bord[2], dist(N, 1e9);
	queue<pi> que;
	que.emplace(0, U[s]);
	que.emplace(1, V[s]);
	dist[U[s]] = dist[V[s]] = 0;
	while(!que.empty()){
		auto x = que.front(); que.pop();
		bord[x.first].push_back(x.second);
		for(auto &i : gph[x.second]){
			if(dist[i] > dist[x.second] + 1){
				dist[i] = dist[x.second] + 1;
				que.emplace(x.first, i);
			}
		}
	}
	int S = -1, T = -1;
	for(int i=0; i<2; i++){
		s = 0, e = (int)bord[i].size() - 1;
		while(s != e){
			int m = (s + e + 1) / 2;
			vector<int> C(bord[i].begin() + m, bord[i].end());
			if(cut_ask(M, C, U, V) != stdist * A) s = m;
			else e = m - 1;
		}
		if(i) S = bord[i][s];
		else T = bord[i][s];
	}
	answer(S, T);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2436 KB Output is correct
2 Correct 4 ms 2444 KB Output is correct
3 Correct 4 ms 2424 KB Output is correct
4 Correct 4 ms 2440 KB Output is correct
5 Correct 4 ms 2424 KB Output is correct
6 Correct 4 ms 2436 KB Output is correct
7 Correct 4 ms 2424 KB Output is correct
8 Correct 4 ms 2436 KB Output is correct
9 Correct 4 ms 2424 KB Output is correct
10 Correct 4 ms 2524 KB Output is correct
11 Correct 4 ms 2424 KB Output is correct
12 Correct 4 ms 2436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2492 KB Output is correct
2 Correct 28 ms 3156 KB Output is correct
3 Correct 201 ms 8476 KB Output is correct
4 Correct 213 ms 8480 KB Output is correct
5 Correct 188 ms 8476 KB Output is correct
6 Correct 176 ms 8408 KB Output is correct
7 Correct 186 ms 8580 KB Output is correct
8 Correct 214 ms 8596 KB Output is correct
9 Correct 195 ms 8640 KB Output is correct
10 Correct 170 ms 8492 KB Output is correct
11 Correct 224 ms 8324 KB Output is correct
12 Correct 197 ms 8392 KB Output is correct
13 Correct 224 ms 8380 KB Output is correct
14 Correct 224 ms 8368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 3144 KB Output is correct
2 Correct 51 ms 3812 KB Output is correct
3 Correct 63 ms 4452 KB Output is correct
4 Correct 166 ms 8164 KB Output is correct
5 Correct 166 ms 8320 KB Output is correct
6 Correct 166 ms 8196 KB Output is correct
7 Correct 181 ms 8512 KB Output is correct
8 Correct 147 ms 8284 KB Output is correct
9 Correct 184 ms 8364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2600 KB Output is correct
2 Correct 45 ms 3092 KB Output is correct
3 Correct 161 ms 7264 KB Output is correct
4 Correct 196 ms 8564 KB Output is correct
5 Correct 213 ms 8564 KB Output is correct
6 Correct 185 ms 8596 KB Output is correct
7 Correct 208 ms 8632 KB Output is correct
8 Correct 207 ms 8536 KB Output is correct
9 Correct 203 ms 8664 KB Output is correct
10 Correct 206 ms 8580 KB Output is correct
11 Correct 199 ms 8332 KB Output is correct
12 Correct 194 ms 8368 KB Output is correct
13 Correct 243 ms 8320 KB Output is correct
14 Correct 184 ms 8328 KB Output is correct
15 Correct 191 ms 8656 KB Output is correct
16 Correct 192 ms 8656 KB Output is correct
17 Correct 191 ms 8372 KB Output is correct
18 Correct 210 ms 8404 KB Output is correct
19 Correct 198 ms 8616 KB Output is correct
20 Correct 219 ms 8432 KB Output is correct
21 Correct 188 ms 9148 KB Output is correct
22 Correct 170 ms 9172 KB Output is correct
23 Correct 193 ms 8924 KB Output is correct
24 Correct 222 ms 9060 KB Output is correct
25 Correct 207 ms 8352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 3152 KB Output is correct
2 Correct 31 ms 3132 KB Output is correct
3 Correct 198 ms 8668 KB Output is correct
4 Correct 244 ms 9040 KB Output is correct
5 Correct 314 ms 9968 KB Output is correct
6 Correct 323 ms 9644 KB Output is correct
7 Correct 302 ms 9632 KB Output is correct
8 Correct 289 ms 9648 KB Output is correct
9 Correct 241 ms 7708 KB Output is correct
10 Correct 232 ms 8068 KB Output is correct
11 Correct 251 ms 8168 KB Output is correct
12 Correct 309 ms 9184 KB Output is correct
13 Correct 318 ms 9512 KB Output is correct
14 Correct 290 ms 9544 KB Output is correct
15 Correct 286 ms 9772 KB Output is correct
16 Correct 268 ms 8488 KB Output is correct
17 Correct 200 ms 9132 KB Output is correct
18 Correct 121 ms 9372 KB Output is correct
19 Correct 191 ms 9176 KB Output is correct
20 Correct 212 ms 9588 KB Output is correct
21 Correct 288 ms 9572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 3176 KB Output is correct
2 Correct 53 ms 3220 KB Output is correct
3 Correct 238 ms 8876 KB Output is correct
4 Correct 242 ms 9004 KB Output is correct
5 Correct 255 ms 9324 KB Output is correct
6 Correct 315 ms 9692 KB Output is correct
7 Correct 237 ms 9032 KB Output is correct
8 Correct 257 ms 9096 KB Output is correct
9 Correct 256 ms 9176 KB Output is correct
10 Correct 248 ms 9692 KB Output is correct
11 Correct 294 ms 9728 KB Output is correct
12 Correct 283 ms 9632 KB Output is correct
13 Correct 238 ms 8340 KB Output is correct
14 Correct 232 ms 8072 KB Output is correct
15 Correct 268 ms 8288 KB Output is correct
16 Correct 240 ms 8052 KB Output is correct
17 Correct 272 ms 8172 KB Output is correct
18 Correct 243 ms 8016 KB Output is correct
19 Correct 285 ms 9112 KB Output is correct
20 Correct 290 ms 9492 KB Output is correct
21 Correct 289 ms 9588 KB Output is correct
22 Correct 285 ms 9508 KB Output is correct
23 Correct 274 ms 9588 KB Output is correct
24 Correct 282 ms 9492 KB Output is correct
25 Correct 262 ms 9788 KB Output is correct
26 Correct 301 ms 9764 KB Output is correct
27 Correct 200 ms 9200 KB Output is correct
28 Correct 230 ms 9340 KB Output is correct
29 Correct 217 ms 9528 KB Output is correct
30 Correct 190 ms 9008 KB Output is correct
31 Correct 203 ms 9164 KB Output is correct
32 Correct 201 ms 9284 KB Output is correct
33 Correct 220 ms 9264 KB Output is correct
34 Correct 208 ms 9304 KB Output is correct
35 Correct 211 ms 9356 KB Output is correct
36 Correct 197 ms 9436 KB Output is correct
37 Correct 189 ms 9508 KB Output is correct
38 Correct 182 ms 9340 KB Output is correct
39 Correct 284 ms 9536 KB Output is correct
40 Correct 275 ms 9660 KB Output is correct
41 Correct 270 ms 9476 KB Output is correct
42 Correct 341 ms 9512 KB Output is correct