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>
std::pair<int,int> a[5555];
void findLocation(int n,int fir,int loc[],int stp[])
{
int i,j,l,r,ld,rd;
loc[0]=fir;
stp[0]=1;
if(n==1)return;
a[0].first=0;
a[0].second=0;
for(i=1;i<n;i++)
{
a[i].first=getDistance(0,i);
a[i].second=i;
}
std::sort(a+1,a+n);
loc[a[1].second]=loc[0]+a[1].first;
stp[a[1].second]=2;
l=0;r=a[1].second;
for(i=2;i<n;i++)
{
ld=getDistance(l,a[i].second);
rd=getDistance(r,a[i].second);
for(j=0;j<i;j++)if(stp[a[j].second]==1&&loc[a[j].second]<loc[l]+ld&&loc[r]-loc[a[j].second]+loc[l]+ld-loc[a[j].second]==rd)break;
if(j<i)
{
loc[a[i].second]=loc[l]+ld;
stp[a[i].second]=2;
if(loc[a[i].second]>loc[r])r=a[i].second;
}
else
{
loc[a[i].second]=loc[r]-rd;
stp[a[i].second]=1;
if(loc[a[i].second]<loc[l])l=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... |