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 <iostream>
#include <algorithm>
#include <vector>
#define rep(i, N) for (int i=0; i<(N); i++)
#define pb push_back
#define _1 first
#define _2 second
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define INF 1145141919
using namespace std;
typedef pair<int, int> P;
int N;
int memo[111][111];
int Rank[111];
int dist(int a, int b) {
if (memo[a][b] != -1) return memo[a][b];
return memo[a][b] = getDistance(a, b);
}
int saien(int x) {
P mp = P(-1, -1);
rep(t, N) mp = max(mp, P(dist(x, t), t));
return mp._2;
}
int hubDistance(int NN, int sub) {
N=NN;
rep(i, N) rep(j, N) memo[i][j] = -1;
rep(i, N) memo[i][i] = 0;
int u = saien(0);
int v = saien(u);
vector<int> pos;
int L = dist(u, v);
pos.pb(0);
pos.pb(L);
rep(x, N) if (x != u && x != v) {
Rank[x] = dist(u, x)+dist(v, x)-dist(u, v);
pos.pb(dist(u, x)-Rank[x]);
}
sort(all(pos)); uniq(pos);
P mp = P(INF, -1);
for (int x : pos) mp = min(mp, P(max(x, L-x), x));
int R = mp._1;
return R;
}
Compilation message (stderr)
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:28:29: warning: unused parameter 'sub' [-Wunused-parameter]
int hubDistance(int NN, 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... |