이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "towns.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
#define ff first
#define ss second
const int maxn = 510;
int n;
int d[maxn][maxn];
int ds[maxn],up[maxn];
map<ii,int> cnt;
int Ask(int u, int v)
{
if (u==v) return 0;
if (u>v) swap(u,v);
if (d[u][v] == -1)
{
d[u][v] = getDistance(u,v);
}
return d[u][v];
}
bool check(int dist)
{
vector<int> to_mid(n+1,0);
for (int i=0; i<n; i++)
if (ds[i]<dist) to_mid[i]=dist-ds[i]+up[i];
else to_mid[i]=ds[i]-dist+up[i];
vector <int> sz(n+1,0);
int alive = 0; int num=1;
for (int i=1; i<n; i++)
if (num==0)
{
num=1;
sz[i]++; alive=i;
}
else
{
if (Ask(i,alive)==to_mid[i]+to_mid[alive])
{
num--; sz[i]++;
}
else
{
num++;
sz[alive]++;
}
}
if (num<=0) return 1;
num=0;
for (int i=0; i<n; i++) if (sz[i]!=0)
{
if (Ask(i,alive)==to_mid[i]+to_mid[alive]) num-=sz[i];
else num+=sz[i];
}
return num<=0;
}
int hubDistance(int N, int sub) {
n=N;
cnt.clear();
for (int i=0; i<n; i++)
for (int j=0; j<n; j++) d[i][j] = -1;
int u,v,dist;
u=0;
for (int i=1; i<n; i++) if (dist<Ask(0,i))
{
u=i;
dist=Ask(0,i);
}
v=0; dist=0;
for (int i=1; i<n; i++) if (dist<Ask(u,i))
{
dist=Ask(u,i);
v=i;
}
int R=1e9;
for (int i=0; i<n; i++)
{
int x=Ask(u,i); int y=Ask(i,0);
int z=Ask(u,0);
up[i] = (x+y-z)/2;
ds[i] = x-up[i];
R=min(R,max(ds[i],dist-ds[i]));
cnt[{ds[i],dist-ds[i]}]++;
}
// int sum = 0;
// int it = 0;
// int dau = -1;
// for (auto i:cnt)
// {
// int sz = i.ss;
// if (max(i.ff.ff,i.ff.ss)==R)
// {
// if (sz<=n/2&&sum<=n/2&&(n-sz-sum<=n/2))
// {
// dau=1;
// it=0;
// break;
// }
// else if (sum<=n/2&&(n-sz-sum)<=n/2)
// {
// it=i.ff.ff;
// }
// }
// sum+=sz;
// }
// if (it!=0)
// {
// if (check(it)) dau=1;
// else dau=-1;
// }
return R;
}
컴파일 시 표준 에러 (stderr) 메시지
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:65:11: warning: variable 'v' set but not used [-Wunused-but-set-variable]
65 | int u,v,dist;
| ^
towns.cpp:60:28: warning: unused parameter 'sub' [-Wunused-parameter]
60 | int hubDistance(int N, int sub) {
| ~~~~^~~
towns.cpp:67:29: warning: 'dist' may be used uninitialized in this function [-Wmaybe-uninitialized]
67 | for (int i=1; i<n; i++) if (dist<Ask(0,i))
| ^~
# | 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... |