# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
556772 | blue | Towns (IOI15_towns) | C++17 | 13 ms | 356 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 <vector>
#include <cmath>
#include <set>
#include <iostream>
using namespace std;
namespace
{
using vi = vector<int>;
}
int hubDistance(int N, int sub)
{
vi dist0(N);
dist0[0] = 0;
for(int i = 1; i < N; i++)
dist0[i] = getDistance(0, i);
int S = 0;
for(int i = 1; i < N; i++)
if(dist0[i] > dist0[S])
S = i;
int ST = 0; //diameter
// cerr << "done\n";
vi distS(N);
distS[S] = 0;
distS[0] = dist0[S];
int T = 0;
ST = distS[0];
for(int i = 1; i < N; i++)
{
if(i != S)
{
distS[i] = getDistance(S, i);
if(distS[i] > ST)
{
ST = distS[i];
T = i;
}
}
}
// cerr << "S = " << S << "\n";
vi S0_dist(N);
for(int i = 0; i < N; i++)
S0_dist[i] = (distS[i] + dist0[i] - distS[0])/2;
vi xcoord(N);
for(int i = 0; i < N; i++)
xcoord[i] = distS[i] - S0_dist[i];
int res = 5'000'000;
for(int i = 0; i < N; i++)
res = min(res, max(xcoord[i], ST - xcoord[i]));
return res;
// int best_diff = 5'000'000;
// set<int> best_coords;
// for(int i = 0; i < N; i++)
// {
// // int ist =
// if(abs(2*xcoord[i] - ST) < best_diff)
// {
// best_coords.clear();
// best_diff = abs(2*xcoord[i] - ST);
// }
// if(abs(2*xcoord[i] - ST) == best_diff)
// best_coords.insert(xcoord[i]);
// }
// // cerr << "best coords = ";
// // for(int b : best_coords) cerr << b << ' ';
// // cerr << '\n';
// // cerr << "returning: \n";
// return *best_coords.rbegin();
}
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... |