# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
990739 |
2024-05-31T06:57:46 Z |
starchan |
Towns (IOI15_towns) |
C++17 |
|
11 ms |
860 KB |
#include<bits/stdc++.h>
#include "towns.h"
using namespace std;
#define in array<int, 2>
#define pb push_back
#define pob pop_back
int hubDistance(int n, int sub)
{
in opt = {0, 0};
for(int i = 1; i < n; i++)
opt = max(opt, {getDistance(i, 0), i});
int a = opt[1]; opt = {0, a};
vector<int> d1(n), d2(n); d1[a] = 0;
for(int i = 0; i < n; i++)
{
if(i == a) continue;
opt = max(opt, {d1[i] = getDistance(i, a), i});
}
auto [D, b] = opt; d2[b] = 0;
map<int, vector<int>> diam; diam[0].pb(a); diam[D].pb(b);
for(int i = 0; i < n; i++)
{
if(i == a || i == b)
continue;
d2[i] = getDistance(i, b);
diam[(d1[i]-d2[i]+D)/2].pb(i);
}
int R = 1e9+1;
vector<vector<int>> vi;
vector<int> dist;
for(auto [X, v]: diam)
{
R = min(R, max(X, D-X));
vi.pb(v); dist.pb(X);
}
int N = vi.size();
//0, 1, .., N-1
//has information for stuff on diameter.
int pre = 0;
for(int i = 0; i < N-2; i++)
{
pre+=vi[i].size();
if(R != max(dist[i+1], D-dist[i+1]))
continue;
if(2*pre > n)
break;
if(2*((int)n-pre-vi[i+1].size()) > n)
continue;
if(2*((int)vi[i+1].size()) <= n)
return R;
//Now we need to check if the i+1th thingie, (as we are accessing) is centroid or not.
//This must be done in <= N/2 queries for AC. <= 2N queries is ok too, if we want good partial score.
int g = vi[i+1][0]; int rt = d1[g]-dist[i+1]; int cnt = 0;
for(auto x: vi[i+1])
{
if(x == g)
continue;
int q_rt = d1[x]-dist[i+1];
if((rt+q_rt) == getDistance(x, g))
{
if(cnt)
cnt--;
else
{
cnt = 1; rt = q_rt;
g = x;
}
}
else
cnt++;
}
int SP = 1;
for(auto x: vi[i+1])
{
if(x == g)
continue;
int q_rt = d1[x]-dist[i+1];
if((rt+q_rt) == getDistance(x, g))
SP++;
}
if((2*SP) <= n)
return R;
}
return -R;
}
Compilation message
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:37:17: warning: conversion from 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
37 | int N = vi.size();
| ~~~~~~~^~
towns.cpp:43:19: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
43 | pre+=vi[i].size();
| ^
towns.cpp:48:36: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
48 | if(2*((int)n-pre-vi[i+1].size()) > n)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
towns.cpp:8:28: warning: unused parameter 'sub' [-Wunused-parameter]
8 | int hubDistance(int n, int sub)
| ~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
856 KB |
Output is correct |
2 |
Correct |
7 ms |
860 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
11 ms |
860 KB |
Output is correct |
5 |
Correct |
10 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
860 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |