이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rail.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
const int inf=1e9;
const int N=5555;
int d[N][N];
int mn[N];
int to[N];
int Q=0;
int lim;
int ask(int i, int j) {
++Q; assert(Q<=lim);
return getDistance(i,j);
}
void findLocation(int n, int p, int ans[], int type[]) {
if (n==1) {
ans[0]=p, type[0]=1; return;
}
lim=n*(n-1)/2;
forn(i,n) mn[i]=inf;
forn(i,n) {
forn(j,i) {
int x = getDistance(i,j);
d[i][j]=d[j][i]=x;
mn[i]=min(mn[i],x);
mn[j]=min(mn[j],x);
}
}
forn(i,n) if (mn[i]==0) exit(1);
forn(i,n) forn(j,n) if (d[i][j]==mn[i]) to[i]=j;
ans[0]=p; type[0]=1;
ans[to[0]]=p+mn[0]; type[to[0]]=2;
ans[to[to[0]]]=ans[to[0]]-mn[to[0]]; type[to[to[0]]]=1;
int f=to[to[0]], s=to[0];
//forn(i,n) {
// forn(j,n) cout<<d[i][j]<<' '; cout<<'\n';
//}
for (int i=0; i<n; ++i) {
if ((i==0) || (i==f) || (i==s)) continue;
int u=to[to[i]], v=to[i];
if (v==f) {
type[i]=2;
ans[i]=ans[f]+mn[i];
continue;
}
if (v==s) {
type[i]=1;
ans[i]=ans[s]-mn[i];
continue;
}
int x=d[f][u], y=d[s][u];
//cout<<"! "<<i<<": "<<u<<' '<<v<<' '<<x<<' '<<y<<' '<<f<<' '<<s<<'\n';
if (x<y) {
int a=d[f][u];
int b=d[f][v];
if (a<b) {
type[i]=2;
ans[i]=ans[f]+d[f][i];
} else {
type[i]=1;
ans[i]=ans[f]+d[f][i]-2*mn[i];
}
} else {
int a=d[s][u];
int b=d[s][v];
if (a<b) {
type[i]=1;
ans[i]=ans[s]-d[s][i];
} else {
type[i]=2;
ans[i]=ans[s]-d[s][i]+2*mn[i];
}
}
}
//forn(i,n) cout<<type[i]<<' '<<ans[i]<<'\n';
}
# | 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... |