This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "rail.h"
#include <algorithm>
#include <vector>
using namespace std;
pair <int,int> A[5000];
vector <int> Up;
vector <int> Down;
int Check[5000];
void findLocation(int N, int First, int location[], int stype[])
{
int i, j, k, Left, Right, Dist, OK;
location[0]=First;
stype[0]=1;
for(i=1 ; i<N ; i++)
A[i]=make_pair(getDistance(0,i),i);
sort(A,A+N);
location[A[1].second]=location[0]+A[1].first;
stype[A[1].second]=2;
for(i=2 ; i<N ; i++)
{
Dist=getDistance(A[1].second,A[i].second);
if(A[i].first==A[1].first+Dist && location[A[1].second]-Dist<location[0])
Check[A[i].second]=Dist;
}
Right=A[1].second;
Up.push_back(A[1].second);
for(i=2 ; i<N ; i++)
if(!Check[A[i].second])
{
OK=1;
Dist=getDistance(Right,A[i].second);
k=Up.size();
for(j=0 ; j<k && OK ; j++)
{
if(location[Up[j]]-location[0]==(location[Up[j]]-location[0])+(Dist-(location[Right]-location[Up[j]])))
{
location[A[i].second]=location[Right]-Dist;
stype[A[i].second]=1;
OK=0;
}
}
if(OK)
{
location[A[i].second]=location[0]+A[i].first;
stype[A[i].second]=2;
Right=A[i].second;
Up.push_back(A[i].second);
}
}
Left=0;
Down.push_back(0);
for(i=2 ; i<N ; i++)
if(Check[A[i].second])
{
OK=1;
Dist=getDistance(Left,A[i].second);
k=Down.size();
for(j=0 ; j<k && OK ; j++)
{
if(Check[Down[j]]==(location[A[1].second]-location[Down[j]])+(Dist-(location[Down[j]]-location[Left])))
{
location[A[i].second]=location[Left]-Dist;
stype[A[i].second]=2;
OK=0;
}
}
if(OK)
{
location[A[i].second]=location[A[1].second]-Check[A[i].second];
stype[A[i].second]=1;
Left=A[i].second;
Down.push_back(A[i].second);
}
}
}
# | 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... |