제출 #788073

#제출 시각아이디문제언어결과실행 시간메모리
788073GusterGoose27도시들 (IOI15_towns)C++17
25 / 100
21 ms468 KiB
#include "towns.h"

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 120;
int dist[MAXN][2];

int _abs(int a) {
	return a < 0 ? -a : a;
}

int hubDistance(int n, int sub) {
	int l = 0;
	int d = 0;
	for (int i = 1; i < n; i++) {
		int cur = getDistance(0, i);
		if (cur > d) {
			l = i;
			d = cur;
		}
	}
	// assert(getDistance(0, l) == d);
	dist[l][0] = 0;
	dist[0][0] = d;
	int r = 0;
	for (int i = 1; i < n; i++) {
		if (i == l) continue;
		dist[i][0] = getDistance(i, l);
		if (dist[i][0] > dist[r][0]) r = i;
	}
	dist[r][1] = 0;
	for (int i = 0; i < n; i++) {
		if (i == r) continue;
		if (i == l) {
			dist[i][1] = dist[r][0];
			continue;
		}
		dist[i][1] = getDistance(i, r);
	}
	int mn = n;
	for (int i = 0; i < n; i++) {
		mn = min(mn, _abs(dist[i][0]-dist[i][1]));
	}
	// return (mn+dist[r][0])/2;
	int sz[4]; fill(sz, sz+4, 0);
	for (int i = 0; i < n; i++) {
		int diff = dist[i][1]-dist[i][0];
		if (diff > mn) sz[0]++;
		else if (diff == mn) sz[1]++;
		else if (diff == -mn) sz[2]++;
		else sz[3]++;
	}
	assert((mn&1) == (dist[r][0]&1));
	int R = (dist[r][0]+mn)/2;
	if (sz[1] && (sz[0] <= n/2 && sz[1] <= n/2 && sz[2]+sz[3] <= n/2)) return R;
	if (sz[2] && (sz[0]+sz[1] <= n/2 && sz[2] <= n/2 && sz[3] <= n/2)) return R;
	return -R;
}

컴파일 시 표준 에러 (stderr) 메시지

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:14:28: warning: unused parameter 'sub' [-Wunused-parameter]
   14 | int hubDistance(int n, int sub) {
      |                        ~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...