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][115], v;
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 T = d[0][v], D = 0;
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[1][i] - d[0][i]) >> 1;
cntr[s]++;
r = min(r, max(s, D - s));
}
int chk = -1, l = 0;
for(auto& x : cntr){
if(l <= N / 2 && N - (l += x.ss) <= N / 2){
if(max(x.ff, D - x.ff) == r){
if(x.ss <= N / 2) return r;
chk = x.ff << 1;
}
}
}
if(chk == -1) return -r;
vector<vector<int> > s, t, de;
vector<int> la;
for(int i = 0; i < N; i++)
if(chk == T + d[1][i] - d[0][i])
s.push_back({i});
while(s.size() > 1){
for(int i = 1; i < s.size(); i += 2){
if(getDistance(s[i - 1][0], s[i][0]) == d[0][s[i - 1][0]] + d[1][s[i][0]] - T){
de.push_back(s[i - 1]);
de.push_back(s[i]);
} else {
for(int& x : s[i - 1])
s[i].push_back(x);
t.push_back(s[i]);
}
}
if(s.size() & 1){
de.push_back(s.back());
la = s.back();
}
swap(s, t);
t.clear();
}
int sz = 0;
if(s.empty()) s.push_back(la);
else sz = s[0].size();
if(s[0].empty()) return r;
for(auto& x : de){
if(getDistance(x[0], s[0][0]) != d[0][s[0][0]] + d[1][x[0]] - T)
sz += x.size();
}
if(sz > N / 2) return -r;
return r;
}
Compilation message (stderr)
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:46:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1; i < s.size(); i += 2){
~~^~~~~~~~~~
towns.cpp:66:21: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
else sz = s[0].size();
~~~~~~~~~^~
towns.cpp:70:17: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
sz += x.size();
^
towns.cpp:9: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... |