# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1087079 | guagua0407 | Towns (IOI15_towns) | C++17 | 12 ms | 1016 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;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int hubDistance(int N, int sub) {
int n=N;
vector<int> dis(n);
for(int i=0;i<n;i++){
dis[i]=getDistance(0,i);
}
int x=max_element(all(dis))-dis.begin();
for(int i=0;i<n;i++){
dis[i]=getDistance(x,i);
}
int y=max_element(all(dis))-dis.begin();
vector<int> dis2(n);
for(int i=0;i<n;i++){
dis2[i]=getDistance(y,i);
}
vector<int> val1(n),val2(n);
vector<int> vec;
for(int i=0;i<n;i++){
vec.push_back(dis[i]-(dis[i]+dis2[i]-dis[y])/2);
val1[i]=dis[i]-(dis[i]+dis2[i]-dis[y])/2;
val2[i]=(dis[i]+dis2[i]-dis[y])/2;
}
sort(all(vec));
int R=dis[y];
int ans=R;
for(auto v:vec){
ans=min(ans,max(v,R-v));
}
map<int,int> mp;
for(auto v:vec){
mp[v]++;
}
bool tf=false;
int pre=0;
for(auto v:mp){
if(max(v.f,R-v.f)==ans){
int mx=max({pre,v.s,n-pre-v.s});
if(mx<=n/2){
tf=true;
}
}
pre+=v.s;
}
if(!tf){
pre=0;
for(auto v:mp){
if(max(v.f,R-v.f)==ans){
if(v.s>n/2){
vector<int> xs;
for(int i=0;i<n;i++){
if(val1[i]==v.f){
xs.push_back(i);
}
}
mt19937 rng(time(NULL));
uniform_int_distribution<int> gen(0,(int)xs.size()-1);
tf=true;
for(int t=0;t<2;t++){
int pos=gen(rng);
int cnt=0;
for(int i=0;i<(int)xs.size();i++){
if(i==pos){
cnt++;
continue;
}
int d=getDistance(xs[i],xs[pos]);
if(d!=val2[xs[i]]+val2[xs[pos]]) cnt++;
}
if(cnt>n/2){
tf=false;
break;
}
}
}
}
pre+=v.s;
}
}
return (tf?ans:-ans);
}
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... |