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];
set<int> virt;
virt.insert(fiC);
location[fiC]=location[d]-dist(d,fiC);
stype[fiC]=1;
for (int _ = 1; _ < left.size(); _++){
int i = left[_];
int vpos = dist(fiC,i);
auto it = virt.lower_bound(vpos);
if (it==virt.begin()){
stype[i]=1;
location[i]=location[d]-dist(d,i);
fiC=i;
virt.insert(fiC);
continue;
}
it--;
if (dist(*it,i)+dist(d,*it)==dist(d,i)){
stype[i]=2;
location[i]=location[fiC]+dist(fiC,i);
}
else {
stype[i]=1;
location[i]=location[d]-dist(d,i);
fiC=i;
virt.insert(fiC);
}
}
}
if (right.size()){
int fiD = right[0];
set<int> virt;
virt.insert(fiD);
location[fiD]=location[c]+dist(c,fiD);
stype[fiD]=2;
for (int _ = 1; _ < right.size(); _++){
int i = right[_];
int vpos = dist(fiD,i);
auto it = virt.lower_bound(vpos);
if (it!=virt.end() && dist(*it,i)+dist(c,*it)==dist(c,i)){ stype[i]=1;
location[i]=location[fiD]-dist(fiD,i);
}
else {
stype[i]=2;
location[i]=location[c]+dist(c,i);
fiD=i;
virt.insert(fiD);
}
}
}
}
Compilation message (stderr)
rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:44:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for (int _ = 1; _ < left.size(); _++){
| ~~^~~~~~~~~~~~~
rail.cpp:74:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for (int _ = 1; _ < right.size(); _++){
| ~~^~~~~~~~~~~~~~
# | 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... |