# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1090675 | owoovo | Towns (IOI15_towns) | C++17 | 11 ms | 1024 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>
#define ll long long
#define F first
#define S second
using namespace std;
const ll maxn=1e18;
ll to0[120],tor1[120],tor2[120];
ll r1,r2;
int getd(int a,int b){
if(a==0)return to0[b];
else if(b==0)return to0[a];
return getDistance(a,b);
}
int hubDistance(int N, int sub) {
for(int i=1;i<N;i++)to0[i]=getDistance(0,i);
ll maxn=0,pos=0;
for(int i=0;i<N;i++){
if(to0[i]>maxn){
maxn=to0[i];
pos=i;
}
}
r1=pos;
for(int i=0;i<N;i++)tor1[i]=getDistance(r1,i);
maxn=0,pos=0;
for(int i=0;i<N;i++){
if(tor1[i]>maxn){
maxn=tor1[i];
pos=i;
}
}
r2=pos;
for(int i=0;i<N;i++)tor2[i]=getDistance(r2,i);
vector<pair<ll,ll>> vc;
for(int i=0;i<N;i++){
//cout<<i<<" "<<tor1[r2]<<" "<<tor1[i]<<" "<<tor2[i]<<"\n";
ll dis=(tor1[r2]+tor1[i]-tor2[i])/2;
vc.push_back({dis,tor1[i]-dis});
}
ll ans=maxn;
for(int i=0;i<N;i++){
ans=min(ans,max(vc[i].F,tor1[r2]-vc[i].F));
}
vector<ll> want;
for(int i=0;i<N;i++){
if(ans==max(vc[i].F,tor1[r2]-vc[i].F)){
want.push_back(vc[i].F);
}
}
int ok=0;
// for(auto dis:want){
// int s=0,m=0,l=0;
// vector<int> now;
// for(int i=0;i<N;i++){
// if(vc[i].F<dis)s++;
// else if(vc[i].F==dis)now.push_back(i);
// else l++;
// }
// if(s>N/2||l>N/2)continue;
// int vis[120]={0},OK=1;
// for(auto x:now){
// if(vis[x])continue;
// int bk=1;
// for(auto y:now){
// if(vis[y])continue;
// int dd=getd(x,y);
// if(dd<vc[x].S+vc[y].S){
// vis[y]=1;
// bk++;
// }
// }
// if(bk>N/2)OK=0;
// }
// ok|=OK;
// }
return ok==1?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... |