# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
588215 | FatihSolak | Wall (IOI14_wall) | C++17 | 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 "rail.h"
#include <bits/stdc++.h>
#define N 5005
using namespace std;
int d[N][N];
int get(int i,int j){
if(i > j)swap(i,j);
if(i == j)return 0;
if(d[i][j])
return d[i][j];
return d[i][j] = getDistance(i,j);
}
void findLocation(int n, int first, int location[], int stype[])
{
for(int i = 0;i<n;i++){
location[i] = -1;
stype[i] = -1;
}
location[0] = first;
stype[0] = 1;
if(n == 1)return;
vector<pair<int,int>> v;
for(int i = 0;i<n;i++){
if(i == 0)continue;
v.push_back({get(0,i),i});
}
sort(v.begin(),v.end());
int last = v[0].second;
int x = last;
set<int> points = {location[last]};
location[v[0].second] = get(0,v[0].second) + first;
stype[v[0].second] = 2;
for(int i = 1;i<v.size();i++){
if(get(0,v[i].second) > 2*get(0,x) && get(0,v[i].second) > get(x,v[i].second) + get(0,x) - 2)
continue;
int nwpoint = location[last] - get(last, v[i].second);
int rval = *points.lower_bound(nwpoint);
if(2*rval - nwpoint + first == get(0,v[i].second)){
location[v[i].second] = nwpoint;
stype[v[i].second] = 1;
}
else{
location[v[i].second] = get(0,v[i].second) + first;
stype[v[i].second] = 2;
last = v[i].second;
points.insert(location[last]);
}
}
for(int i = 1;i<v.size();i++){
if(stype[v[i].second] != -1)continue;
location[v[i].second] = first - (get(0,v[i].second) - 2*get(0,x)) ;
stype[v[i].second] = 1;
}
// for(int i = 0;i<n;i++){
// cout << location[i] << " " << stype[i] << endl;
// }
// cout << endl;
}