# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1018734 |
2024-07-10T09:04:02 Z |
parsadox2 |
Towns (IOI15_towns) |
C++17 |
|
13 ms |
1012 KB |
#include "towns.h"
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
const int N = 1e2 + 20;
int n , dis[N][N] , r[N] , L[N] , R[N] , cnt[N];
bool Solve(int D)
{
return true;
int lef = 0 , rig = 0 , mid = 0;
for(int x = 0 ; x < n ; x++)
cnt[x] = 0;
vector <int> vec;
for(int x = 0 ; x < n ; x++)
{
if(L[x] < D)
lef++;
else if(L[x] > D)
rig++;
else
{
bool flg = false;
for(auto u : vec)
{
dis[u][x] = dis[x][u] = getDistance(u , x);
if(dis[u][x] != r[u] + r[x])
{
flg = true;
cnt[u]++;
break;
}
}
if(!flg)
{
vec.push_back(x);
cnt[x] = 1;
}
}
}
for(int i = 0 ; i < n ; i++)
mid = max(mid , cnt[i]);
return (lef <= n / 2 && rig <= n/2 && mid <= n / 2);
}
int hubDistance(int nn , int sub) {
n = nn;
pair <int , int> D = make_pair(0 , 1);
for(int i = 1 ; i < n ; i++)
{
dis[0][i] = dis[i][0] = getDistance(0 , i);
if(dis[0][i] > dis[D.F][D.S])
D = make_pair(0 , i);
}
for(int i = 0 ; i < n ; i++) if(i != D.S)
{
dis[i][D.S] = dis[D.S][i] = getDistance(i , D.S);
if(dis[i][D.S] > dis[D.F][D.S])
D = make_pair(i , D.S);
}
int ans = dis[D.F][D.S];
for(int x = 0 ; x < n ; x++)
{
dis[x][D.F] = dis[D.F][x] = getDistance(x , D.F);
r[x] = (dis[x][D.F] + dis[x][D.S] - dis[D.F][D.S]) / 2;
L[x] = dis[x][D.F] - r[x];
R[x] = dis[x][D.S] - r[x];
//cout << x << " : " << L[x] << " " << R[x] << endl;
ans = min(ans , max(L[x] , R[x]));
}
ans = -ans;
set <int> st;
for(int x = 0 ; x < n ; x++) if(L[x] == abs(ans) || R[x] == abs(ans))
{
if(st.find(L[x]) != st.end())
continue;
st.insert(L[x]);
if(Solve(L[x]))
{
break;
ans = abs(ans);
}
}
return ans;
}
Compilation message
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:50:30: warning: unused parameter 'sub' [-Wunused-parameter]
50 | int hubDistance(int nn , int sub) {
| ~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
348 KB |
Output is correct |
2 |
Correct |
7 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
13 ms |
540 KB |
Output is correct |
5 |
Correct |
9 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
348 KB |
Output is correct |
2 |
Correct |
7 ms |
860 KB |
Output is correct |
3 |
Correct |
9 ms |
860 KB |
Output is correct |
4 |
Correct |
9 ms |
1012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |