# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
113292 | TadijaSebez | 도시들 (IOI15_towns) | C++11 | 23 ms | 564 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "towns.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=120;
int n,cen,den;
int a[N],b[N],len[N],pl[N];
int d[N][N],diam;
bool was[N][N];
int Ask(int i, int j)
{
if(i==j) return 0;
if(!was[i][j]) d[i][j]=d[j][i]=getDistance(i,j);
was[i][j]=was[j][i]=1;
return d[i][j];
}
bool Compare(int u, int v)
{
return len[u]+len[v]!=Ask(u,v);
}
bool Try(int d)
{
vector<int> work;
int lo=1,hi=1;
for(int i=0;i<n;i++) if(i!=cen && i!=den)
{
int tmp=pl[i];
if(tmp<d) lo++;
if(tmp>d) hi++;
if(tmp==d) work.pb(i);
}
if(lo>n/2 || hi>n/2) return 0;
//Boyer-Moore majority vote algorithm
vector<int> store,sz;
vector<int> ok(work.size(),0);
int balance=0;
for(int i=0;i<work.size();i++)
{
if(balance==0) store.pb(i),sz.pb(1),balance++;
else
{
if(Compare(work[i],work[store.back()]))
{
balance++;
ok[i]=1;
sz[sz.size()-1]++;
}
else balance--;
}
}
int last=work[store.back()];
int cnt=sz.back();
for(int i=0;i+1<store.size();i++)
{
if(Compare(work[store[i]],last)) cnt+=sz[i];
else
{
for(int j=store[i];j<store[i+1];j++) if(!ok[j])
{
if(Compare(work[j],last)) cnt++;
}
}
}
return cnt<=n/2;
}
int hubDistance(int _N, int sub)
{
srand(time(0));
n=_N;cen=den=0;
for(int i=0;i<n;i++) for(int j=0;j<n;j++) was[i][j]=0;
for(int i=0;i<n;i++) a[i]=b[i]=0;
for(int i=1;i<n;i++)
{
a[i]=Ask(0,i);
if(a[i]>a[cen]) cen=i;
}
for(int i=0;i<n;i++) if(i!=cen)
{
b[i]=Ask(cen,i);
if(b[i]>b[den]) den=i;
}
diam=b[den];
int pre=(a[cen]-a[den]+b[den])/2;
int ans=diam,cnt=0,lo=1,hi=1,goal=diam/2;
for(int i=0;i<n;i++) if(i!=cen && i!=den)
{
pl[i]=(a[cen]+b[i]-a[i])/2;
int tmp=pl[i];
if(tmp<=pre)
{
if(abs(ans-goal)>abs(tmp-goal)) ans=tmp,cnt=0;
if(ans==tmp) cnt++;
}
len[i]=(a[i]+b[i]-a[cen])/2;
}
bool ok=0;
if(Try(ans) || Try(diam-ans)) ok=1;
ans=max(ans,diam-ans);
if(ok) return ans;
else return -ans;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |