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;
map<pair<int,int>,int> mp;
int dist(int a, int b){
if (mp.count({a,b})) return mp[{a,b}];
return mp[{a,b}]=getDistance(a,b);
}
void findLocation(int N, int first, int location[], int stype[])
{
int c = 0, d = 1;
for (int i = 2; i < N; i++){
if (dist(c,i)<dist(c,d)) d=i;
}
vector<int> left;
vector<int> right;
stype[c]=1,stype[d]=2;
location[c]=first,location[d]=first+dist(c,d);
for (int i = 0; i < N; i++){
if (i==c || i==d) continue;
if (dist(c,i)==dist(c,d)+dist(d,i)){
if (dist(d,i)<dist(c,d)){
location[i]=location[d]-dist(d,i);
stype[i]=1;
}
else left.push_back(i);
}
else {
right.push_back(i);
}
}
sort(left.begin(), left.end(), [&](int a, int b){
return dist(d,a)<dist(d,b);
});
sort(right.begin(), right.end(), [&](int a, int b){
return dist(c,a)<dist(c,b);
});
if (left.size()){
int fiC = left[0];
location[fiC]=location[d]-dist(d,fiC);
stype[fiC]=1;
for (int i = 1; i < left.size(); i++){
if (dist(d,left[i])==dist(d,fiC)+dist(fiC,left[i])){
stype[left[i]]=2;
location[left[i]]=location[fiC]+dist(fiC,left[i]);
}
else {
stype[left[i]]=1;
location[left[i]]=location[d]-dist(d,left[i]);
fiC=left[i];
}
}
}
if (right.size()){
int fiD = right[0];
location[fiD]=location[c]+dist(c,fiD);
stype[fiD]=2;
for (int i = 1; i < right.size(); i++){
if (dist(c,right[i])==dist(c,fiD)+dist(fiD,right[i])){
stype[right[i]]=1;
location[right[i]]=location[fiD]-dist(fiD,right[i]);
}
else {
stype[right[i]]=2;
location[right[i]]=location[c]+dist(c,right[i]);
fiD=right[i];
}
}
}
}
Compilation message (stderr)
rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:42:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int i = 1; i < left.size(); i++){
| ~~^~~~~~~~~~~~~
rail.cpp:58:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for (int i = 1; i < right.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... |