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>
#define ff first
#define ss second
using namespace std;
int d[2][200], v = 0;
map<int, int> cntr;
int hubDistance(int N, int sub) {
memset(d, 0,sizeof d);
cntr.clear();
for(int i = 0 ; i < N; i++)
if(d[0][v] < (d[0][i] = getDistance(0, i)))
v = i;
int D = 0;
int T = d[0][v];
for(int i = 0; i < N; i++)
D = max(D, d[1][i] = getDistance(v, i));
int r = 1000000000;
for(int i = 0; i < N; i++){
int s = (T - d[0][i] + d[1][i]) >> 1;
cntr[s]++;
r = min(r, max(s, D - s));
}
int chk = -1;
int l = 0;
for(auto& x : cntr){
if(l <= N / 2){
l += x.ss;
if(N - l <= N / 2){
if(max(D - x.ff, x.ff) == r){
if(x.ss <= N / 2) return r;
chk = x.ff << 1;
}
}
}
}
if(chk == -1) return -r;
vector<int> s, t, o;
for(int i = 0; i < N; i++)
if(T + d[1][i] - d[0][i] == chk)
s.push_back(i);
o = s;
while(s.size() > 1){
for(int i = 1; i < s.size(); i += 2)
if(getDistance(s[i], s[i - 1]) != d[0][s[i]] + d[1][s[i - 1]] - T)
t.push_back(s[i]);
if(s.size() & 1)
t.push_back(s.back());
swap(s, t);
t.clear();
}
if(s.size() == 0) return r;
int sz = 0;
for(int& x : o)
if(getDistance(s[0], x) != d[0][x] + d[1][s[0]] - T)
sz++;
if(sz > N / 2) return -r;
return r;
}
Compilation message (stderr)
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:48:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1; i < s.size(); i += 2)
~~^~~~~~~~~~
towns.cpp:8: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... |