이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include "rail.h"
#define U 1
#define D 0
#define L 0
#define R 1
void findLocation(int N, int first, int location[], int stype[])
{
stype[0] = 1;
location[0] = first;
std::pair<int, int> d[N-1];
for(int i = 1; i < N; i++)
{
d[i-1].first = getDistance(0, i);
d[i-1].second = i;
}
std::sort(d, d+N-1);
int hinge = d[0].second;
int ends[2][2];
for(int i = 0; i < 2; i++)
for(int j = 0; j < 2; j++)
ends[i][j] = -1;
ends[U][L] = ends[U][R] = d[0].second;
ends[D][R] = 0;
location[hinge] = d[0].first + first;
stype[hinge] = 2;
for(int i = 1; i < N-1; i++)
{
int u = d[i].second;
int a = getDistance(u, hinge);
if(a + d[0].first == d[i].first)
{
if(ends[D][L] == -1)
{
ends[D][L] = u;
location[u] = location[hinge] - a;
stype[u] = 1;
continue;
}
int b = getDistance(u, ends[D][L]);
int x = location[ends[D][L]] + 2*(location[ends[U][L]] - location[ends[D][L]]) - b;
int y = location[hinge] - a;
if(x == y)
{
location[u] = x;
stype[u] = 1;
ends[D][L] = u;
}
else
{
location[u] = location[ends[D][L]] + b;
stype[u] = 2;
if(location[u] < location[ends[U][L]])
ends[U][L] = u;
}
}
else
{
int b = getDistance(u, ends[U][R]);
int x = b + location[ends[U][R]] - 2*(location[ends[U][R]] - location[ends[D][R]]);
int y = d[i].first + first;
if(x == y)
{
location[u] = x;
stype[u] = 2;
ends[U][R] = u;
}
else
{
location[u] = location[ends[U][R]] - b;
stype[u] = 1;
if(location[u] > location[ends[D][R]])
ends[D][R] = u;
}
}
}
}
# | 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... |