이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rail.h"
#include<iostream>
#include<vector>
using namespace std;
using pii = pair<int, int>;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define forsn(i, s, n) for(int i=s; i<(int)n; ++i)
#define PB push_back
#define F first
#define S second
const int MAXN=5010, INF=1000000010;
int *rel, *res, count, le[2], ri[2];
int n, dis[MAXN][MAXN];
bool vis[MAXN];
vector<pii> g[MAXN];
void dfs(int v){
vis[v]=true, ++count;
for(pii to:g[v]) if(!vis[to.F]){
if(res[v]==1) rel[to.F]=rel[v]+to.S;
else rel[to.F]=rel[v]-to.S;
int tp=(res[v]==1);
if(rel[le[tp]]>rel[to.F]) le[tp]=to.F;
if(rel[ri[tp]]<rel[to.F]) ri[tp]=to.F;
res[to.F]=tp+1;
dfs(to.F);
}
}
void findLocation(int N, int first, int location[], int stype[])
{
n=N;
forn(i, n) forsn(j, i, n) dis[i][j]=dis[j][i]=getDistance(i, j);
forn(i, n){
int mn=INF, ind=-1;
forn(j, n) if(j!=i && mn>dis[i][j]) mn=dis[i][j], ind=j;
g[i].PB({ind, mn}), g[ind].PB({i, mn});
}
rel=location, res=stype;
rel[0]=first, res[0]=1;
dfs(0);
while(count!=n){
int mn=INF, ind=-1, type=-1, coord=-1;
forn(i, n) if(!vis[i]) forn(j, 2){
if(mn>dis[le[j]][i]) mn=dis[le[j]][i], type=j^1, coord=rel[le[j]]+(j? -mn : mn), ind=i;
if(mn>dis[ri[j]][i]) mn=dis[ri[j]][i], type=j^1, coord=rel[ri[j]]+(j? -mn : mn), ind=i;
}
rel[ind]=coord, stype[ind]=type+1;
if(rel[le[type]]>rel[ind]) le[type]=ind;
if(rel[ri[type]]<rel[ind]) ri[type]=ind;
dfs(ind);
}
}
# | 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... |