This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include "towns.h"
using namespace std;
const int MAXN = 110;
const int MAXD = 1e6 + 10;
int dist[MAXN][MAXN];
int hubDistance(int N, int sub)
{
int A = 0, B = 0;
for(int i = 1; i < N; i++)
{
dist[0][i] = dist[i][0] = getDistance(0, i);
if(dist[0][i] > dist[0][A]) A = i;
}
B = A;
for(int i = 0; i < N; i++)
{
if(i != 0 && i != A)
dist[A][i] = dist[i][A] = getDistance(A, i);
if(dist[A][i] > dist[A][B]) B = i;
}
if(B != 0)
for(int i = 1; i < N; i++)
if(i != A)
dist[B][i] = dist[i][B] = getDistance(B, i);
int d = dist[A][B], R = d, DA = d;
for(int i = 0; i < N; i++)
{
if(i == A || i == B) continue;
int da = dist[A][B] + dist[A][i] - dist[i][B];
da /= 2;
if(max(da, d - da) <= R) DA = da;
R = min(R, max(da, d - da));
}
int s[3] = {1, 0, 1};
for(int i = 0; i < N; i++)
{
if(i == A || i == B) continue;
int da = dist[A][B] + dist[A][i] - dist[i][B];
da /= 2;
if(da < DA) s[0]++;
if(da == DA)s[1]++;
if(da > DA) s[2]++;
}
int mx = max(s[0], max(s[1], s[2]));
if(mx > N / 2) R *= -1;
return R;
}
Compilation message (stderr)
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:9:28: warning: unused parameter 'sub' [-Wunused-parameter]
9 | int hubDistance(int N, int sub)
| ~~~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |