# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
778287 | boris_mihov | Towns (IOI15_towns) | C++17 | 16 ms | 1100 KiB |
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 "towns.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
typedef long long llong;
const int MAXN = 100000 + 10;
const int INF = 1e9;
int query(int u, int v)
{
return getDistance(u - 1, v - 1);
}
int distA[MAXN];
int distB[MAXN];
int distC[MAXN];
int hubDistance(int n, int sub)
{
int max = 0;
int dist = 0;
for (int i = 2 ; i <= n ; ++i)
{
distA[i] = query(1, i);
if (distA[i] > dist)
{
max = i;
dist = distA[i];
}
}
dist = 0;
int end = 0;
for (int i = 1 ; i <= n ; ++i)
{
distB[i] = query(max, i);
if (distB[i] > dist)
{
end = i;
dist = distB[i];
}
}
int diff = INF;
for (int i = 1 ; i <= n ; ++i)
{
distC[i] = query(i, end);
diff = std::min(diff, abs(distB[i] - distC[i]));
}
return (distB[end] + diff) / 2;
}
Compilation message (stderr)
# | 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... |