# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
395352 | jjang36524 | Rail (IOI14_rail) | C++14 | 110 ms | 656 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 "rail.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;
int zero[3001];
int one[3001];
int op;
void findLocation(signed N, signed first, signed location[], signed stype[])
{
int i;
pair<int,int>mi={1LL<<60,1};
for(i=1;i<N;i++)
{
zero[i]=getDistance(0,i);
mi=min(mi,make_pair(zero[i],i));
}
stype[0]=1;
location[mi.second]=mi.first;
stype[mi.second]=2;
one[0]=mi.first;
vector<pair<int,int>>le;
vector<pair<int,int>>re;
for(i=0;i<N;i++)
{
if(i==mi.second||i==0)
continue;
one[i]=getDistance(mi.second,i);
if(zero[i]==one[i]+mi.first)
le.push_back({one[i],i});
else
re.push_back({zero[i],i});
}
sort(le.begin(),le.end());
sort(re.begin(),re.end());
for(i=0;i<le.size();i++)
{
stype[le[i].second]=1;
location[le[i].second]=mi.first-le[i].first;
int firstdis=0;
int firstp=0;
int j;
for(j=i-1;j>=0;j--)
{
if(stype[le[j].second]==1)
{
firstdis=getDistance(le[i].second,le[j].second);
firstp=location[le[j].second];
break;
}
}
for(j=0;j<i;j++)
{
if(stype[le[j].second]==1)
{
if(firstdis-location[le[j].second]+firstp+one[le[j].second]==one[le[i].second])
{
stype[le[i].second]=2;
location[le[i].second]=firstp+firstdis;
break;
}
}
}
}
for(i=0;i<re.size();i++)
{
stype[re[i].second]=2;
location[re[i].second]=re[i].first;
int firstdis=0;
int firstp=0;
int j;
for(j=i-1;j>=0;j--)
{
if(stype[re[j].second]==2)
{
firstdis=getDistance(re[i].second,re[j].second);
firstp=location[re[j].second];
break;
}
}
for(j=0;j<i;j++)
{
if(stype[re[j].second]==2)
{
if(firstdis+location[re[j].second]-firstp+zero[re[j].second]==zero[re[i].second])
{
stype[re[i].second]=1;
location[re[i].second]=firstp-firstdis;
break;
}
}
}
}
for(i=0;i<N;i++)
location[i]+=first;
}
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... |