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>
#include "rail.h"
using namespace std;
int d[5001][5001];
int ask(int i,int j){
if(i==j)return 0;
if(d[i][j])return d[i][j];
d[i][j] = d[j][i] = getDistance(i,j);
return d[i][j];
}
void findLocation(int n, int f, int location[], int stype[])
{
location[0] = f;
stype[0] = 1;
//find the closest guy to 0
int mnn = 1e9;
int x = 0;
vector<int>l,r;
for(int i=1;i<n;i++){
if(mnn > ask(0,i)){
mnn = ask(0,i);
x = i;
}
}
stype[x] = 2;
location[x] = f + ask(0,x);
for(int i=0;i<n;i++){
if(i!=0 && i!=x){
if(ask(0,i) == ask(0,x) + ask(x,i))l.push_back(i);
else r.push_back(i);
}
}
vector<pair<int,int>>a;
for(int y:r)a.push_back({ask(0,y),y});
sort(a.begin(),a.end());
int last = x;
for(auto Z : a){
int z = Z.second;
//case 1 d(y,z) > d(0,z)
//case 2 d(y,z) < d(0,z);
if(ask(last,z) > ask(0,z)){ //type D
stype[z] = 2;
location[z] = location[0] + ask(0,z);
last = z;
}else{ //type C
stype[z] = 1;
location[z] = location[last] - ask(last,z);
}
}
//solving for left side is symmetric
a.clear();
for(int y:l)a.push_back({ask(x,y),y});
sort(a.begin(),a.end());
last = 0;
for(auto Z : a){
int z = Z.second;
//case 1 d(y,z) > d(x,z)
//case 2 d(y,z) < d(x,z);
if(ask(last,z) > ask(x,z)){ //type c
stype[z] = 1;
location[z] = location[x] - ask(x,z);
last = z;
}else{
stype[z] = 2;
location[z] = location[last] + ask(last,z);
}
}
//for(int i=0;i<n;i++)cout<<stype[i]<<" "<<location[i]<<'\n';
}
# | 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... |