답안 #1010524

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1010524 2024-06-29T07:36:54 Z 정민찬(#10827) 통행료 (IOI18_highway) C++17
51 / 100
125 ms 10556 KB
#include "highway.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

long long ask(const std::vector<int> &w);
void answer(int s, int t);

vector<vector<pair<int,int>>> adj;
vector<int> dist;

void getDist(int st) {
	int N = adj.size();
	vector<int> vis(N, 0);
	queue<int> q;
	q.push(st);
	dist[st] = 0;
	vis[st] = 1;
	while (!q.empty()) {
		int x = q.front();
		q.pop();
		for (auto &[y, _] : adj[x]) {
			if (!vis[y]) {
				dist[y] = dist[x] + 1;
				vis[y] = 1;
				q.push(y);
			}
		}
	}
}

void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
	adj.resize(N);
	int M = U.size();
	for (int i=0; i<M; i++) {
		adj[U[i]].push_back({V[i], i});
		adj[V[i]].push_back({U[i], i});
	}
	int cnt = 0;
	assert(cnt <= 51); cnt ++;
	ll mndist = ask(vector<int>(M, 0));
	int s = 0, e = N-1;
	while (s < e) {
		int mid = s + e >> 1;
		vector<int> w(M, 0);
		for (int i=s; i<=mid; i++) {
			for (auto &[j, k] : adj[i]) {
				w[k] = 1;
			}
		}
		assert(cnt <= 51); cnt ++;
		ll ret = ask(w);
		if (ret == mndist) s = mid + 1;
		else e = mid;
	}
	int rt = s;
	dist.assign(N, 0);
	getDist(rt);
	vector<int> idx(N);
	iota(idx.begin(), idx.end(), 0);
	sort(idx.begin(), idx.end(), [&] (int &x, int &y) { return dist[x] > dist[y]; });
	s = 0; e = N-1;
	while (s < e) {
		int mid = s + e >> 1;
		vector<int> w(M, 0);
		for (int i=0; i<=mid; i++) {
			for (auto &[j, k] : adj[idx[i]]) {
				w[k] = 1;
			}
		}
		assert(cnt <= 51); cnt ++;
		ll ret = ask(w);
		if (ret == mndist) s = mid + 1;
		else e = mid;
	}
	int u = idx[s];
	getDist(u);
	vector<int> cand;
	for (int i=0; i<N; i++) {
		if ((ll)A * (ll)dist[i] == mndist) {
			cand.push_back(i);
		}
	}
	s = 0; e = cand.size() - 1;
	while (s < e) {
		int mid = s + e >> 1;
		vector<int> w(M, 0);
		for (int i=s; i<=mid; i++) {
			for (auto &[j, k] : adj[cand[i]]) {
				w[k] = 1;
			}
		}
		assert(cnt <= 51); cnt ++;
		ll ret = ask(w);
		if (ret == mndist) s = mid + 1;
		else e = mid;
	}
	int v = cand[s];
	answer(u, v);
}

Compilation message

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:45:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   45 |   int mid = s + e >> 1;
      |             ~~^~~
highway.cpp:65:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   65 |   int mid = s + e >> 1;
      |             ~~^~~
highway.cpp:87:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   87 |   int mid = s + e >> 1;
      |             ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 10 ms 1368 KB Output is correct
3 Correct 99 ms 8772 KB Output is correct
4 Correct 94 ms 8656 KB Output is correct
5 Correct 92 ms 8532 KB Output is correct
6 Correct 93 ms 8432 KB Output is correct
7 Correct 97 ms 8720 KB Output is correct
8 Correct 99 ms 8444 KB Output is correct
9 Correct 98 ms 8528 KB Output is correct
10 Correct 97 ms 8776 KB Output is correct
11 Correct 88 ms 7828 KB Output is correct
12 Correct 95 ms 7828 KB Output is correct
13 Correct 93 ms 7832 KB Output is correct
14 Correct 86 ms 7828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1108 KB Output is correct
2 Correct 14 ms 2188 KB Output is correct
3 Correct 27 ms 2892 KB Output is correct
4 Correct 71 ms 7824 KB Output is correct
5 Correct 75 ms 7832 KB Output is correct
6 Correct 64 ms 7644 KB Output is correct
7 Correct 70 ms 7964 KB Output is correct
8 Correct 81 ms 7680 KB Output is correct
9 Correct 67 ms 7836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 9 ms 1252 KB Output is correct
3 Correct 75 ms 6680 KB Output is correct
4 Correct 96 ms 8420 KB Output is correct
5 Correct 91 ms 8420 KB Output is correct
6 Correct 89 ms 8632 KB Output is correct
7 Correct 85 ms 8416 KB Output is correct
8 Correct 95 ms 8644 KB Output is correct
9 Correct 83 ms 8648 KB Output is correct
10 Correct 101 ms 8668 KB Output is correct
11 Correct 87 ms 7832 KB Output is correct
12 Correct 82 ms 7832 KB Output is correct
13 Correct 82 ms 7824 KB Output is correct
14 Correct 80 ms 7840 KB Output is correct
15 Correct 87 ms 8448 KB Output is correct
16 Correct 86 ms 8428 KB Output is correct
17 Correct 89 ms 8144 KB Output is correct
18 Correct 92 ms 7828 KB Output is correct
19 Correct 94 ms 8428 KB Output is correct
20 Correct 97 ms 7960 KB Output is correct
21 Correct 81 ms 9368 KB Output is correct
22 Correct 84 ms 9064 KB Output is correct
23 Correct 84 ms 8892 KB Output is correct
24 Correct 82 ms 8988 KB Output is correct
25 Correct 93 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1288 KB Output is correct
2 Correct 10 ms 1368 KB Output is correct
3 Correct 110 ms 9028 KB Output is correct
4 Correct 106 ms 9336 KB Output is correct
5 Correct 125 ms 10376 KB Output is correct
6 Incorrect 113 ms 10212 KB Output is incorrect: {s, t} is wrong.
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1368 KB Output is correct
2 Correct 10 ms 1332 KB Output is correct
3 Correct 107 ms 8856 KB Output is correct
4 Correct 120 ms 9188 KB Output is correct
5 Correct 112 ms 9564 KB Output is correct
6 Incorrect 117 ms 10556 KB Output is incorrect: {s, t} is wrong.
7 Halted 0 ms 0 KB -