이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "towns.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pf printf
#define pb push_back
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
typedef vector<int> vi;
typedef pair<int,int> ii;
map<int,int> memo[150];
inline int ask(int a,int b){
if(a==b)return 0;
if(memo[a].find(b)!=memo[a].end())return memo[a][b];
return memo[a][b]=memo[b][a]=getDistance(a,b);
}
int hubDistance(int N,int sub){
for(int i=0;i<N;++i)memo[i].clear();
int a=0,b=0;
for(int i=0;i<N;++i)if(ask(0,i)>ask(0,a))a=i;
for(int i=0;i<N;++i)if(ask(a,i)>ask(a,b))b=i;
int ans=ask(a,b);
vector<pair<int,ii>> v;
for(int i=0;i<N;++i){
int ab=ask(a,b),ai=ask(a,i),bi=ask(b,i);
int da=(ab+ai-bi)/2;
int di=ai-da;
v.pb({da,{di,i}});
ans=min(ans,max(da,ab-da));
}
sort(all(v));
for(int i=0;i<N;++i){
if(max(v[i].fi,ask(a,b)-v[i].fi)!=ans)continue;
int l=i,r=i;
while(r<N-1&&v[r].fi==v[r+1].fi)++r;
if(l>N/2||N-r>N/2)continue;
vector<ii> cur,nxt;
for(int i=l;i<=r;++i)cur.pb(v[i].se);
int rep=-1;
while(!cur.empty()){
for(int i=0;i<sz(cur);i+=2){
if(i+1==sz(cur)){
rep=cur[i].se;
}
else{
int x=cur[i].se,y=cur[i+1].se;
if(ask(a,x)+ask(a,y)-ask(x,y)>2*v[l].fi){
nxt.pb(cur[i]);
}
}
}
swap(cur,nxt);
nxt.clear();
}
if(rep==-1)return ans;
/*
int num=0;
for(int i=l;i<=r;++i){
int x=rep,y=i;
if(ask(a,x)+ask(a,y)-ask(x,y)>2*v[l].fi)++num;
}
if(num<=N/2)return ans;
*/
}
return -ans;
}
컴파일 시 표준 에러 (stderr) 메시지
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:49:11: warning: declaration of 'i' shadows a previous local [-Wshadow]
49 | for(int i=l;i<=r;++i)cur.pb(v[i].se);
| ^
towns.cpp:42:10: note: shadowed declaration is here
42 | for(int i=0;i<N;++i){
| ^
towns.cpp:53:12: warning: declaration of 'i' shadows a previous local [-Wshadow]
53 | for(int i=0;i<sz(cur);i+=2){
| ^
towns.cpp:42:10: note: shadowed declaration is here
42 | for(int i=0;i<N;++i){
| ^
towns.cpp:22:27: warning: unused parameter 'sub' [-Wunused-parameter]
22 | int hubDistance(int N,int sub){
| ~~~~^~~
# | 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... |