답안 #116268

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
116268 2019-06-11T19:52:59 Z Bruteforceman 도시들 (IOI15_towns) C++11
25 / 100
19 ms 912 KB
#include "towns.h"
#include "bits/stdc++.h"
using namespace std;

map <pair <int, int>, int> mp;

int distance(int i, int j) {
	if(i == j) return 0;
	if(i > j) swap(i, j);
	if(mp.find(make_pair(i, j)) != mp.end()) return mp[make_pair(i, j)];
	return mp[make_pair(i, j)] = getDistance(i, j);
}
int hubDistance(int N, int sub) {
	mp.clear();
	int opt = 0;
	int dist = 0;
	for(int i = 1; i < N; i++) {
		int d = distance(0, i);
		if(d > dist) {
			dist = d;
			opt = i;
		}
	}
	int P = 0, Q = opt;
	dist = 0;
	for(int i = 0; i < N; i++) {
		if(i == opt) continue;
		int d = distance(opt, i);
		if(d > dist) {
			dist = d;
			P = i;
		}
	}
	int R = distance(P, Q);
	for(int i = 0; i < N; i++) {
		int lca_dist = (distance(i, P) + distance(i, Q) - distance(P, Q)) / 2;
		int p_dist = distance(i, P) - lca_dist;
		R = min(R, max(p_dist, distance(P, Q) - p_dist));
	}
	return R;
}

Compilation message

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:13:28: warning: unused parameter 'sub' [-Wunused-parameter]
 int hubDistance(int N, int sub) {
                            ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 384 KB Output is correct
2 Correct 14 ms 896 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 19 ms 912 KB Output is correct
5 Correct 19 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 384 KB Output is correct
2 Correct 17 ms 768 KB Output is correct
3 Correct 18 ms 896 KB Output is correct
4 Correct 19 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -