#include "towns.h"
#include <bits/stdc++.h>
using namespace std ;
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define vii vector<ii>
int from[115] , to[115] , dist[115][115] ;
vii len[1000010] ;
int hubDistance(int n, int sub) {
memset(dist , -1 , sizeof dist) ;
int mdist = -1 , opt = -1 , tmp ;
for(int i=0;i<n;i++){
tmp = getDistance(0 , i) ;
if(mdist < tmp){
mdist = tmp ;
opt = i ;
}
}
mdist = -1 ;
int nxt = -1 ;
for(int i=0;i<n;i++){
from[i] = getDistance(opt , i) ;
if(from[i] > mdist){
mdist = from[i] ;
nxt = i;
}
}
for(int i=0;i<n;i++) to[i] = getDistance(nxt , i ) ;
for(int i=1;i<=1000000;i++) len[i].clear() ;
int res = 1e9 ;
for(int i=0;i<n;i++){
if(i == nxt ||i == opt) continue ;
int ok = (from[i] + to[i] - mdist)/2 ;
int ln = from[i] - ok ;
len[ln].push_back({i , ok }) ;
res = min(res , max( mdist - ln , ln ) ) ;
}
if(sub <= 2) return res ;
int sum = 1 ;
bool chk = 0 ;
for(int i=1;i<=mdist;i++){
if(len[i].empty()) continue ;
if(max(i , mdist - i) == res) {
if( (int)len[i].size() <= n/2 && sum<=n/2 && n - sum - (int)len[i].size() <= n/2 ) chk = 1 ;
}
sum += (int)len[i].size() ;
}
if(chk ) return res ;
else return -res ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
25556 KB |
Output is correct |
2 |
Correct |
103 ms |
25556 KB |
Output is correct |
3 |
Correct |
6 ms |
25556 KB |
Output is correct |
4 |
Correct |
109 ms |
25556 KB |
Output is correct |
5 |
Correct |
103 ms |
25556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
25556 KB |
Output is correct |
2 |
Correct |
113 ms |
25556 KB |
Output is correct |
3 |
Correct |
109 ms |
25556 KB |
Output is correct |
4 |
Correct |
106 ms |
25556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
99 ms |
25556 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
183 ms |
25556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
99 ms |
25556 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
93 ms |
25556 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |