답안 #1010501

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1010501 2024-06-29T07:24:53 Z 정민찬(#10827) 통행료 (IOI18_highway) C++17
51 / 100
134 ms 10548 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});
	}
	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;
			}
		}
		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;
			}
		}
		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;
			}
		}
		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:43:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   43 |   int mid = s + e >> 1;
      |             ~~^~~
highway.cpp:62:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   62 |   int mid = s + e >> 1;
      |             ~~^~~
highway.cpp:83:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   83 |   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 1 ms 344 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 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 1 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 0 ms 344 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 9 ms 1368 KB Output is correct
3 Correct 90 ms 8872 KB Output is correct
4 Correct 95 ms 8416 KB Output is correct
5 Correct 99 ms 8532 KB Output is correct
6 Correct 88 ms 8888 KB Output is correct
7 Correct 96 ms 8736 KB Output is correct
8 Correct 111 ms 8424 KB Output is correct
9 Correct 103 ms 8428 KB Output is correct
10 Correct 99 ms 8776 KB Output is correct
11 Correct 89 ms 7836 KB Output is correct
12 Correct 101 ms 7836 KB Output is correct
13 Correct 91 ms 7836 KB Output is correct
14 Correct 88 ms 7980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1112 KB Output is correct
2 Correct 14 ms 2096 KB Output is correct
3 Correct 21 ms 2700 KB Output is correct
4 Correct 65 ms 7836 KB Output is correct
5 Correct 65 ms 7836 KB Output is correct
6 Correct 65 ms 7636 KB Output is correct
7 Correct 63 ms 7840 KB Output is correct
8 Correct 65 ms 7828 KB Output is correct
9 Correct 64 ms 7836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 9 ms 1112 KB Output is correct
3 Correct 66 ms 6664 KB Output is correct
4 Correct 86 ms 8424 KB Output is correct
5 Correct 87 ms 8424 KB Output is correct
6 Correct 89 ms 8432 KB Output is correct
7 Correct 89 ms 8432 KB Output is correct
8 Correct 87 ms 8412 KB Output is correct
9 Correct 88 ms 8344 KB Output is correct
10 Correct 95 ms 8676 KB Output is correct
11 Correct 88 ms 7812 KB Output is correct
12 Correct 85 ms 7840 KB Output is correct
13 Correct 88 ms 7828 KB Output is correct
14 Correct 84 ms 7832 KB Output is correct
15 Correct 99 ms 8440 KB Output is correct
16 Correct 91 ms 8432 KB Output is correct
17 Correct 81 ms 7828 KB Output is correct
18 Correct 90 ms 7836 KB Output is correct
19 Correct 100 ms 8432 KB Output is correct
20 Correct 82 ms 8028 KB Output is correct
21 Correct 86 ms 9316 KB Output is correct
22 Correct 74 ms 8912 KB Output is correct
23 Correct 77 ms 8904 KB Output is correct
24 Correct 73 ms 8972 KB Output is correct
25 Correct 97 ms 7996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1368 KB Output is correct
2 Correct 11 ms 1368 KB Output is correct
3 Correct 106 ms 9104 KB Output is correct
4 Correct 126 ms 9440 KB Output is correct
5 Correct 134 ms 10436 KB Output is correct
6 Incorrect 119 ms 10300 KB Output is incorrect: {s, t} is wrong.
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1364 KB Output is correct
2 Correct 9 ms 1368 KB Output is correct
3 Correct 110 ms 9072 KB Output is correct
4 Correct 107 ms 9204 KB Output is correct
5 Correct 116 ms 9600 KB Output is correct
6 Incorrect 125 ms 10548 KB Output is incorrect: {s, t} is wrong.
7 Halted 0 ms 0 KB -