이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// M
#include<bits/stdc++.h>
#include "rail.h"
using namespace std;
const int N = 5005;
int n, D[N][N];
int Dist(int i, int j)
{
if (D[j][i] != -1)
D[i][j] = D[j][i];
if (D[i][j] == -1)
D[i][j] = D[j][i] = getDistance(i, j);
return D[i][j];
}
void findLocation(int _n, int loc0, int location[], int stype[])
{
n = _n;
location[0] = loc0;
stype[0] = 1;
memset(D, -1, sizeof(D));
for (int i = 0; i < n; i ++)
D[i][i] = 0;
int nw = 1;
for (int i = 1; i < n; i ++)
if (Dist(0, i) < Dist(0, nw))
nw = i;
location[nw] = location[0] + Dist(0, nw);
stype[nw] = 2;
vector < int > L, R;
for (int i = 1; i < n; i ++)
if (i != nw && Dist(0, nw) + Dist(nw, i) == Dist(0, i))
L.push_back(i);
else if (i != nw)
R.push_back(i);
L.push_back(0);
sort(L.begin(), L.end(), [&](int i, int j){return Dist(nw, i) < Dist(nw, j);});
int now = nw, last = -1;
for (int i : L)
{
if (last == -1)
{
stype[i] = 1;
location[i] = location[nw] - Dist(nw, i);
last = i;
continue;
}
if (Dist(last, i) < location[now] - location[last])
{
now = i;
stype[now] = 2;
location[now] = location[last] + Dist(last, i);
continue;
}
else
{
stype[i] = 1;
location[i] = location[nw] - Dist(nw, i);
last = i;
}
}
int st = L[0];
for (int i : R)
D[st][i] = Dist(nw, i) - Dist(nw, st);
sort(R.begin(), R.end(), [&](int i, int j){return Dist(st, i) < Dist(st, j);});
now = st;
last = -1;
for (int i : R)
{
if (last == -1)
{
stype[i] = 2;
location[i] = location[st] + Dist(st, i);
last = i;
continue;
}
if (Dist(last, i) < location[last] - location[now])
{
now = i;
stype[now] = 1;
location[now] = location[last] - Dist(last, i);
continue;
}
else
{
stype[i] = 2;
location[i] = location[st] + Dist(st, i);
last = i;
}
}
return ;
}
# | 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... |