답안 #97351

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
97351 2019-02-15T12:37:38 Z E869120 통행료 (IOI18_highway) C++14
57 / 100
362 ms 16676 KB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;

int N, M, U[1 << 18], V[1 << 18], dist[1 << 18], par[1 << 18], paredge[1 << 18];
vector<pair<int, int>> G[1 << 18]; bool anti[1 << 18];

void find_pair(int NN, vector<int> UU, vector<int> VV, int A, int B) {
	// ----------------------------- Step 0: Input ---------------------------
	N = NN; M = UU.size();
	for (int i = 0; i < M; i++) { U[i] = UU[i]; V[i] = VV[i]; }
	
	// -------------------------- Step 1: Get All-A --------------------------
	vector<int> W(M, 0);
	long long BASE = ask(W), DIST = BASE / A;
	
	// ---------------------- Step 2: The Minimum Vertex ---------------------
	int c1 = 0;
	for (int i = 16; i >= 0; i--) {
		for (int j = 0; j < M; j++) {
			if (min(U[j], V[j]) >= c1 + (1 << i)) W[j] = 0;
			else W[j] = 1;
		}
		long long p1 = ask(W);
		if (p1 == BASE) { c1 += (1 << i); }
	}
	
	// -------------------------- Step 3: Make Tree --------------------------
	for (int i = 0; i < M; i++) {
		if (min(U[i], V[i]) < c1) continue;
		G[U[i]].push_back(make_pair(V[i], i));
		G[V[i]].push_back(make_pair(U[i], i));
	}
	
	for (int i = 0; i < N; i++) dist[i] = (1 << 30);
	
	queue<int> que; que.push(c1); dist[c1] = 0;
	while (!que.empty()) {
		int pos1 = que.front(); que.pop();
		
		for (int i = 0; i < G[pos1].size(); i++) {
			int to = G[pos1][i].first;
			if (dist[to] > dist[pos1] + 1) {
				dist[to] = dist[pos1] + 1;
				que.push(to);
			}
		}
	}
	
	for (int i = c1 + 1; i < N; i++) {
		for (int j = 0; j < G[i].size(); j++) {
			int to = G[i][j].first;
			if (dist[i] > dist[to]) { par[i] = to; paredge[i] = G[i][j].second; break; }
		}
	}
	
	// ---------------------------- 4. Find T --------------------------------
	vector<pair<int, int>> V;
	for (int i = c1 + 1; i < N; i++) {
		if (dist[i] == (1 << 30)) continue;
		V.push_back(make_pair(dist[i], i));
	}
	sort(V.begin(), V.end());
	
	//for (int i = 0; i < V.size(); i++) cout << "V[" << i << "] = " << V[i].second << endl;
	
	int c2 = 0;
	for (int i = 16; i >= 0; i--) {
		for (int j = 0; j < W.size(); j++) W[j] = 1;
		for (int j = 0; j < c2 + (1 << i); j++) {
			if (j >= V.size()) break;
			W[paredge[V[j].second]] = 0;
		}
		long long p2 = ask(W);
		if (p2 != BASE) c2 += (1 << i);
	}
	
	// --------------------- 5. Find the candidate of S ----------------------
	long long T = V[c2].second, cand_dst = DIST - dist[T];
	if (cand_dst == 0) {
		answer(T, c1);
		return;
	}
	
	int cx = T; anti[cx] = true;
	while (true) {
		cx = par[cx];
		anti[cx] = true;
		if (cx == c1) break;
	}
	
	vector<int> V2;
	for (int i = c1 + 1; i < N; i++) {
		if (dist[i] == cand_dst && anti[i] == false) V2.push_back(i);
	}
	
	// ----------------------------- 6. Find S --------------------------------
	int c3 = 0;
	for (int i = 16; i >= 0; i--) {
		for (int j = 0; j < W.size(); j++) W[j] = 1;
		for (int j = c1 + 1; j < W.size(); j++) W[paredge[j]] = 0;
		
		for (int j = 0; j < c3 + (1 << i); j++) {
			if (j >= V2.size()) break;
			W[paredge[V2[j]]] = 1;
		}
		long long p3 = ask(W);
		if (p3 == BASE) c3 += (1 << i);
	}
	
	long long S = V2[c3];
	answer(S, T);
	return;
}

Compilation message

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:41:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < G[pos1].size(); i++) {
                   ~~^~~~~~~~~~~~~~~~
highway.cpp:51:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j < G[i].size(); j++) {
                   ~~^~~~~~~~~~~~~
highway.cpp:69:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j < W.size(); j++) W[j] = 1;
                   ~~^~~~~~~~~~
highway.cpp:71:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (j >= V.size()) break;
        ~~^~~~~~~~~~~
highway.cpp:100:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j < W.size(); j++) W[j] = 1;
                   ~~^~~~~~~~~~
highway.cpp:101:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = c1 + 1; j < W.size(); j++) W[paredge[j]] = 0;
                        ~~^~~~~~~~~~
highway.cpp:104:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (j >= V2.size()) break;
        ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 6500 KB Output is correct
2 Correct 7 ms 6392 KB Output is correct
3 Correct 8 ms 6520 KB Output is correct
4 Correct 8 ms 6392 KB Output is correct
5 Correct 11 ms 6392 KB Output is correct
6 Correct 8 ms 6520 KB Output is correct
7 Correct 8 ms 6492 KB Output is correct
8 Correct 8 ms 6440 KB Output is correct
9 Correct 8 ms 6392 KB Output is correct
10 Correct 7 ms 6504 KB Output is correct
11 Correct 8 ms 6504 KB Output is correct
12 Correct 8 ms 6392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 6568 KB Output is correct
2 Correct 35 ms 7500 KB Output is correct
3 Correct 220 ms 14504 KB Output is correct
4 Correct 209 ms 14508 KB Output is correct
5 Correct 204 ms 14508 KB Output is correct
6 Correct 197 ms 14492 KB Output is correct
7 Correct 252 ms 14528 KB Output is correct
8 Correct 189 ms 14616 KB Output is correct
9 Correct 183 ms 14564 KB Output is correct
10 Correct 231 ms 14512 KB Output is correct
11 Correct 219 ms 13960 KB Output is correct
12 Correct 221 ms 13960 KB Output is correct
13 Correct 226 ms 13960 KB Output is correct
14 Correct 256 ms 13968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 7288 KB Output is correct
2 Correct 43 ms 8036 KB Output is correct
3 Correct 55 ms 7668 KB Output is correct
4 Correct 185 ms 12172 KB Output is correct
5 Correct 151 ms 12164 KB Output is correct
6 Correct 179 ms 13336 KB Output is correct
7 Correct 162 ms 9752 KB Output is correct
8 Correct 165 ms 12464 KB Output is correct
9 Correct 163 ms 10616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 6524 KB Output is correct
2 Correct 33 ms 7496 KB Output is correct
3 Correct 165 ms 12124 KB Output is correct
4 Correct 207 ms 13008 KB Output is correct
5 Correct 234 ms 13792 KB Output is correct
6 Correct 198 ms 12520 KB Output is correct
7 Correct 206 ms 13472 KB Output is correct
8 Correct 218 ms 13092 KB Output is correct
9 Correct 229 ms 14360 KB Output is correct
10 Correct 212 ms 14476 KB Output is correct
11 Correct 223 ms 13288 KB Output is correct
12 Correct 262 ms 13956 KB Output is correct
13 Correct 240 ms 13964 KB Output is correct
14 Correct 239 ms 13576 KB Output is correct
15 Correct 222 ms 13972 KB Output is correct
16 Correct 219 ms 12952 KB Output is correct
17 Correct 227 ms 13588 KB Output is correct
18 Correct 210 ms 13252 KB Output is correct
19 Correct 167 ms 12432 KB Output is correct
20 Correct 203 ms 13064 KB Output is correct
21 Correct 201 ms 13524 KB Output is correct
22 Correct 213 ms 12256 KB Output is correct
23 Correct 226 ms 15108 KB Output is correct
24 Correct 247 ms 14976 KB Output is correct
25 Incorrect 261 ms 14016 KB Output is incorrect: {s, t} is wrong.
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 7416 KB Output is correct
2 Correct 34 ms 7580 KB Output is correct
3 Correct 239 ms 14776 KB Output is correct
4 Correct 264 ms 14608 KB Output is correct
5 Correct 309 ms 16032 KB Output is correct
6 Correct 320 ms 15536 KB Output is correct
7 Correct 335 ms 15956 KB Output is correct
8 Correct 320 ms 16200 KB Output is correct
9 Correct 219 ms 11352 KB Output is correct
10 Correct 258 ms 11408 KB Output is correct
11 Correct 185 ms 10808 KB Output is correct
12 Correct 308 ms 14528 KB Output is correct
13 Correct 286 ms 16204 KB Output is correct
14 Correct 321 ms 15952 KB Output is correct
15 Correct 305 ms 16020 KB Output is correct
16 Correct 297 ms 14832 KB Output is correct
17 Correct 212 ms 14964 KB Output is correct
18 Correct 228 ms 14400 KB Output is correct
19 Correct 203 ms 14984 KB Output is correct
20 Correct 229 ms 13852 KB Output is correct
21 Correct 328 ms 16584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 34 ms 7540 KB Output is partially correct
2 Partially correct 35 ms 7464 KB Output is partially correct
3 Partially correct 253 ms 14400 KB Output is partially correct
4 Partially correct 256 ms 14768 KB Output is partially correct
5 Partially correct 268 ms 14556 KB Output is partially correct
6 Partially correct 299 ms 16332 KB Output is partially correct
7 Partially correct 249 ms 14560 KB Output is partially correct
8 Correct 236 ms 15140 KB Output is correct
9 Correct 262 ms 15460 KB Output is correct
10 Partially correct 316 ms 16648 KB Output is partially correct
11 Partially correct 331 ms 15812 KB Output is partially correct
12 Partially correct 319 ms 16676 KB Output is partially correct
13 Correct 242 ms 11384 KB Output is correct
14 Correct 267 ms 14292 KB Output is correct
15 Correct 254 ms 12812 KB Output is correct
16 Correct 239 ms 12428 KB Output is correct
17 Correct 226 ms 10796 KB Output is correct
18 Correct 270 ms 12964 KB Output is correct
19 Partially correct 288 ms 15152 KB Output is partially correct
20 Partially correct 284 ms 15728 KB Output is partially correct
21 Partially correct 321 ms 15500 KB Output is partially correct
22 Partially correct 320 ms 15356 KB Output is partially correct
23 Partially correct 325 ms 16424 KB Output is partially correct
24 Partially correct 309 ms 16140 KB Output is partially correct
25 Partially correct 309 ms 13648 KB Output is partially correct
26 Partially correct 321 ms 16656 KB Output is partially correct
27 Partially correct 220 ms 13824 KB Output is partially correct
28 Correct 212 ms 13788 KB Output is correct
29 Partially correct 216 ms 13632 KB Output is partially correct
30 Partially correct 197 ms 12780 KB Output is partially correct
31 Partially correct 221 ms 14388 KB Output is partially correct
32 Partially correct 215 ms 13332 KB Output is partially correct
33 Partially correct 207 ms 14356 KB Output is partially correct
34 Correct 206 ms 14888 KB Output is correct
35 Partially correct 230 ms 14980 KB Output is partially correct
36 Partially correct 230 ms 13572 KB Output is partially correct
37 Partially correct 228 ms 13908 KB Output is partially correct
38 Partially correct 221 ms 13012 KB Output is partially correct
39 Partially correct 331 ms 16588 KB Output is partially correct
40 Partially correct 298 ms 16664 KB Output is partially correct
41 Partially correct 362 ms 16604 KB Output is partially correct
42 Partially correct 328 ms 16536 KB Output is partially correct