# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
788084 | GusterGoose27 | Towns (IOI15_towns) | C++17 | 16 ms | 352 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 <bits/stdc++.h>
using namespace std;
const int MAXN = 120;
const int inf = 1e9;
int dist[MAXN][2];
int _abs(int a) {
return a < 0 ? -a : a;
}
int hubDistance(int n, int sub) {
int l = 0;
int d = 0;
for (int i = 1; i < n; i++) {
int cur = getDistance(0, i);
if (cur > d) {
l = i;
d = cur;
}
}
assert(getDistance(0, l) == d);
dist[l][0] = 0;
dist[0][0] = d;
int r = 0;
for (int i = 1; i < n; i++) {
if (i == l) continue;
dist[i][0] = getDistance(i, l);
if (dist[i][0] > dist[r][0]) r = i;
}
dist[r][1] = 0;
for (int i = 0; i < n; i++) {
if (i == r) continue;
if (i == l) {
dist[i][1] = dist[r][0];
continue;
}
dist[i][1] = getDistance(i, r);
}
int mn = inf;
for (int i = 0; i < n; i++) {
mn = min(mn, _abs(dist[i][0]-dist[i][1]));
}
// return (mn+dist[r][0])/2;
int sz[4]; fill(sz, sz+4, 0);
for (int i = 0; i < n; i++) {
int diff = dist[i][1]-dist[i][0];
if (diff > mn) sz[0]++;
else if (diff == mn) sz[1]++;
else if (diff == -mn) sz[2]++;
else sz[3]++;
}
// assert(dist[l][1] == dist[r][0]);
// assert(l != r && l != 0);
assert((mn+dist[r][0])%2 == 0);
int R = (dist[r][0]+mn)/2;
if (sz[1] && (sz[0] <= n/2 && sz[1] <= n/2 && sz[2]+sz[3] <= n/2)) return R;
if (sz[2] && (sz[0]+sz[1] <= n/2 && sz[2] <= n/2 && sz[3] <= n/2)) return R;
return -R;
}
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... |