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>
using namespace std;
#define pii pair<int, int>
#define F first
#define S second
int dist[5005][5005];
int INF=1e9;
int d(int x, int y){
if(dist[x][y]!=0) return dist[x][y];
return dist[x][y]=dist[y][x]=getDistance(x, y);
}
void findLocation(int N, int una, int location[], int stype[]){
stype[0]=1;
location[0]=una;
pii mini={1e9, -1};
for(int i=1;i<N;i++){
mini=min(mini, {d(0, i), i});
}
int x=mini.S;
location[x]=location[0]+mini.F;
stype[x]=2;
vector<pii>L, R;
for(int i=1;i<N;i++){
if(i!=x){
if(d(0, x)+d(x, i)==d(0, i)) L.push_back({d(0, i), i});
else R.push_back({d(0, i), i});
}
}
sort(L.begin(), L.end());
sort(R.begin(), R.end());
vector<int>cur;
for(int i=0;i<R.size();i++){
int y=R[i].S, idx;
bool b=false;
for(int j:cur){
if(d(0, y)==d(0, j)+d(j, y)){
b=true;
idx=j;
}
}
if(!b){
stype[y]=2;
location[y]=location[0]+d(0, y);
cur.push_back(y);
}
else{
stype[y]=1;
location[y]=location[idx]-d(idx, y);
}
}
cur.clear();
for(int i=0;i<L.size();i++){
int y=L[i].S, idx;
bool b=false;
for(int j:cur){
if(d(x, y)==d(x, j)+d(j, y)){
b=true;
idx=j;
}
}
if(!b){
stype[y]=1;
location[y]=location[x]-d(x, y);
cur.push_back(y);
}
else{
stype[y]=2;
location[y]=location[idx]+d(idx, y);
}
}
/*for(int i=0;i<N;i++){
cout<<stype[i]<<" "<<location[i]<<endl;
}*/
}
Compilation message (stderr)
rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:33:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for(int i=0;i<R.size();i++){
| ~^~~~~~~~~
rail.cpp:53:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int i=0;i<L.size();i++){
| ~^~~~~~~~~
# | 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... |