#include "towns.h"
#include <bits/stdc++.h>
using namespace std;
int hubDistance(int n, int sub) {
map<pair<int, int>, int> mp;
auto Ask = [&](int l, int r) {
if (l > r) {
swap(l, r);
}
if (l == r) {
return 0;
}
if (mp.count({l, r})) {
return mp[{l, r}];
}
return getDistance(l, r);
int x;
cin >> x;
mp[{l, r}] = x;
return x;
};
int x = 0, y = 0;
for (int i = 1; i < n; i++) {
if (Ask(0, i) > Ask(0, x)) {
x = i;
}
}
for (int i = 0; i < n; i++) {
if (Ask(x, i) > Ask(x, y)) {
y = i;
}
}
vector<int> d;
vector<int> my(n);
for (int i = 0; i < n; i++) {
my[i] = (Ask(i, x) + Ask(i, 0) - Ask(0, x)) / 2;
d.push_back(my[i]);
}
sort(d.begin(), d.end());
d.erase(unique(d.begin(), d.end()));
int sz = (int) d.size();
vector<int> r(sz);
for (int i = 0; i < sz; i++) {
r[i] = max(d[i], Ask(x, y) - d[i]);
}
int mn = *min_element(r.begin(), r.end());
vector<int> cnt(sz);
for (int i = 0; i < n; i++) {
int idx = (int) (lower_bound(d.begin(), d.end(), my[i]) - d.begin());
cnt[idx] += 1;
}
vector<int> pref(sz);
for (int i = 0; i < sz; i++) {
if (i > 0) {
pref[i] = pref[i - 1];
}
pref[i] += cnt[i];
}
vector<int> cands;
for (int i = 0; i < sz; i++) {
if (r[i] == mn && max((i == 0 ? 0 : pref[i - 1]), pref[sz - 1] - pref[i]) <= n / 2) {
cands.push_back(i);
}
}
return mn;
}
Compilation message
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:6:28: warning: unused parameter 'sub' [-Wunused-parameter]
6 | int hubDistance(int n, int sub) {
| ~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |