Submission #167465

#TimeUsernameProblemLanguageResultExecution timeMemory
167465faremyTowns (IOI15_towns)C++14
25 / 100
27 ms1172 KiB
#include "towns.h"

#include <algorithm>
#include <iostream>


const int MAXN = 110;

int distToEnd[MAXN];


int hubDistance(int N, int sub)
{
	int farthest = 0, end = 0;
	for (int iNode = 0; iNode < N; iNode++)
	{
		int dist = getDistance(0, iNode);
		if (dist > farthest)
		{
			farthest = dist;
			end = iNode;
		}
	}

	int diameter = 0, otherEnd = end;
	for (int iNode = 0; iNode < N; iNode++)
	{
		distToEnd[iNode] = getDistance(end, iNode);
		if (distToEnd[iNode] > diameter)
		{
			diameter = distToEnd[iNode];
			otherEnd = iNode;
		}
	}

	int minMaxDist = diameter;
	for (int iNode = 0; iNode < N; iNode++)
	{
		int distToOth = getDistance(iNode, otherEnd);
		int half = (diameter + distToEnd[iNode] - distToOth) / 2;
		minMaxDist = std::min(minMaxDist, std::max(half, diameter - half));
	}

	return minMaxDist;
}

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:12:28: warning: unused parameter 'sub' [-Wunused-parameter]
 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...