# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
795573 | medmdg | Rail (IOI14_rail) | C++14 | 0 ms | 0 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 <bits/stdc++.h>
#pragma once
#include "rail.h"
using ll =long long;
ll LINF=1000000000000000000;
int INF=1000000000;
#define pi pair<int,int>
#define pl pair<ll,ll>
#define endl '\n'
#define vi vector<int>
#define vii vector<vector<int>>
#define vl vector<ll>
#define vll vector<vector<ll>>
using namespace std;
int minind(vi &v){
int mn=v[0];
int m=0;
for(int i=1;i<v.size();i++){
if(v[i]<mn){
mn=v[i];
m=i;
}
}
return m;
}
int getDistance(int i, int j);
void findLocation(int n, int first, int location[], int stype[]){
for(int i=0;i<n;i++){
location[i]=0;
stype[i]=0;
}
vi d0(n),ds(n);
for(int i=1;i<n;i++){
d0[i]= getDistance(0,i);
}
d0[0]=INF;
int second=minind(d0);
d0[0]=0;
for(int i=1;i<n;i++){
if(i==second)continue;
int dist= getDistance(i,second);
ds[i]=dist;
}
stype[0]=1;
stype[second]=2;
location[0]=first;
location[second]=first+d0[second];
for(int i=0;i<n;i++){
if(stype[i])continue;
if(d0[i]<d0[second] && ds[i]<d0[second]){
stype[i]=1;
location[i]=first+d0[i];
}
}
vector<pi>right,left;
for(int i=0;i<n;i++){
if(stype[i])continue;
if(d0[i]==d0[second]+ds[i]){
left.push_back(make_pair(ds[i],i));
}
else right.push_back(make_pair(d0[i],i));
}
std::sort(right.begin(), right.end());
std::sort(left.begin(), left.end());
int last=second;
for(auto p:right){
int i=p.second;
int dist= getDistance(i,last);
if(d0[i]<dist){
stype[i]=1;
location[i]= location[last]-dist;
}
else{
stype[i]=2;
location[i]=first+d0[i];
last=i;
}
}
last = 0;
for( auto p:left){
int i=p.second;
int dist= getDistance(i,last);
if(ds[i]<dist){
stype[i]=2;
location[i]=location[last]+dist;
}
else {
stype[i]=1;
location[i]=location[second]-ds[i];
last=i;
}
}