# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
430773 | Amylopectin | Rail (IOI14_rail) | C++14 | 100 ms | 580 KiB |
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 <iostream>
#include <stdio.h>
#include <algorithm>
#include "rail.h"
//#include "grader.cpp"
using namespace std;
const int mxn = 5010,mxi = 1e9 + 10;
struct we
{
int ind,dis;
};
bool cmp(const struct we &l,const struct we &r)
{
return l.dis < r.dis;
}
struct we le[mxn] = {},ri[mxn] = {};
int fr0[mxn] = {},frc[mxn] = {},lli[mxn] = {},rli[mxn] = {};
void findLocation(int n, int stn, int aloc[], int asty[])
{
int i,j,cmi = mxi,cn = -1,rul = 0,rur = 0,col = 0,cor = 0,cl,cr,mid,cva,cdif,cpo;
for(i=1; i<n; i++)
{
fr0[i] = getDistance(0,i);
if(fr0[i] < cmi)
{
cmi = fr0[i];
cn = i;
}
}
for(i=1; i<n; i++)
{
if(i != cn)
{
frc[i] = getDistance(cn,i);
if(fr0[i] - frc[i] != cmi)
{
ri[rur] = {i,fr0[i]};
rur ++;
}
else
{
le[rul] = {i,frc[i]};
rul ++;
}
}
}
aloc[0] = stn;
asty[0] = 1;
aloc[cn] = stn + fr0[cn];
asty[cn] = 2;
sort(le,le+rul,cmp);
sort(ri,ri+rur,cmp);
if(rul > 0)
{
while(le[col].dis < cmi && col < rul-1)
{
lli[col] = le[col].ind;
aloc[lli[col]] = aloc[cn] - le[col].dis;
asty[lli[col]] = 1;
col ++;
}
lli[col] = le[col].ind;
aloc[lli[col]] = aloc[cn] - le[col].dis;
asty[lli[col]] = 1;
col ++;
}
for(i=col; i<rul; i++)
{
cpo = aloc[lli[col-1]] + getDistance(lli[col-1],le[i].ind);
cl = 0;
cr = col-1;
while(cl < cr)
{
mid = (cl+cr) / 2;
if(aloc[lli[mid]] <= cpo)
{
cr = mid;
}
else
{
cl = mid+1;
}
}
if(aloc[cn] - aloc[lli[cl]] + cpo - aloc[lli[cl]] == le[i].dis && cpo < aloc[0])
{
aloc[le[i].ind] = cpo;
asty[le[i].ind] = 2;
}
else
{
aloc[le[i].ind] = aloc[cn] - le[i].dis;
asty[le[i].ind] = 1;
lli[col] = le[i].ind;
col ++;
}
}
if(rur > 0)
{
rli[0] = ri[0].ind;
aloc[rli[0]] = aloc[0] + ri[0].dis;
asty[rli[0]] = 2;
cor ++;
}
for(i=1; i<rur; i++)
{
cpo = aloc[rli[cor-1]] - getDistance(rli[cor-1],ri[i].ind);
cl = 0;
cr = cor-1;
while(cl < cr)
{
mid = (cl+cr) / 2;
if(aloc[rli[mid]] < cpo)
{
cl = mid + 1;
}
else
{
cr = mid;
}
}
if(aloc[rli[cl]] * 2 - aloc[0] - cpo == ri[i].dis && cpo > aloc[cn])
{
aloc[ri[i].ind] = cpo;
asty[ri[i].ind] = 1;
}
else
{
aloc[ri[i].ind] = aloc[0] + ri[i].dis;
asty[ri[i].ind] = 2;
rli[cor] = ri[i].ind;
cor ++;
}
}
// for(i=0; i<n; i++)
// {
// printf("for %d : %d %d\n",i,aloc[i],asty[i]);
// }
return ;
}
//int main()
//{
// cout << "Hello world!" << endl;
// return 0;
//}
Compilation message (stderr)
# | 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... |