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 <algorithm>
using namespace std;
int n;
int d0[110];
int d1[110];
int dist[110];
bool checkSame(int i, int j) {
return (getDistance(i, j) != dist[i] + dist[j]);
}
bool chk[110];
bool check(int p) {
int l = 0, r = 0;
vector<int> vt;
for (int i = 0; i < n; ++i) {
if (d1[i] - dist[i] < p) ++l;
else if (d1[i] - dist[i] > p) ++r;
else vt.push_back(i);
}
if (vt.empty() || l > n / 2 || r > n / 2) return false;
int st, sum = 0;
vector<int> gr;
for (int i = 0; i < vt.size(); ++i) {
if (sum == 0) {
gr.push_back(st = i);
sum = 1;
}
else {
if (chk[i] = checkSame(vt[st], vt[i])) ++sum;
else --sum;
}
}
sum = (sum + (vt.size() - st)) / 2;
for (int i = 1; i < gr.size(); ++i) {
if (checkSame(vt[gr[i - 1]], vt[st])) sum += (gr[i] - gr[i - 1]) / 2;
else {
for (int j = gr[i - 1] + 1; j < gr[i]; ++j) {
if (chk[j]) continue;
if (checkSame(vt[j], vt[st])) ++sum;
}
}
}
return sum <= n / 2;
}
int hubDistance(int N, int sub) {
n = N;
int p = 0, d = 0;
for (int i = 1; i < n; ++i) {
d0[i] = getDistance(0, i);
if (d < d0[i]) {
d = d0[i];
p = i;
}
}
d1[0] = d;
d1[p] = 0;
for (int i = 1; i < n; ++i) {
if (i == p) continue;
d1[i] = getDistance(p, i);
d = max(d1[i], d);
}
int r = 2e9;
dist[0] = 0;
dist[p] = 0;
for (int i = 1; i < n; ++i) {
if (i == p) continue;
dist[i] = (d0[i] + d1[i] - d1[0]) / 2;
r = min(r, abs(d - 2 * (d1[i] - dist[i])));
}
int ans = (d + r) / 2;
if (check((d + r) / 2) || (r != 0 && check((d - r) / 2))) return ans;
return -ans;
}
Compilation message (stderr)
towns.cpp: In function 'bool check(int)':
towns.cpp:29:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < vt.size(); ++i) {
^
towns.cpp:35:41: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
if (chk[i] = checkSame(vt[st], vt[i])) ++sum;
^
towns.cpp:39:6: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
sum = (sum + (vt.size() - st)) / 2;
^
towns.cpp:40:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < gr.size(); ++i) {
^
towns.cpp: At global scope:
towns.cpp:52:28: warning: unused parameter 'sub' [-Wunused-parameter]
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... |