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 <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
const int INF = 0x3f3f3f3f;
bool ckmin(auto& a, const auto& b) {return b<a?a=b,1:0;}
struct appl // apparent location
{
public:
int i, x;
appl(int _i=-1, int _x=0): i(_i), x(_x) {}
bool operator < (const appl& o) const {return x < o.x;}
bool operator > (const appl& o) const {return x > o.x;}
};
void findLocation(int N, int first, int location[], int stype[])
{
int A=0, B, bestd=INF;
std::vector<int> da(N), db(N);
for(int i=1;i<N;++i)
{
da[i]=getDistance(A, i);
if(ckmin(bestd, da[i]))
B=i;
}
location[A] = first;
stype[A] = 1;
location[B] = first + da[B];
stype[B] = 2;
std::vector<appl> left, right;
int AB = da[B];
int dbmin = da[B];
for(int i=0;i<N;++i)
if(i != A && i != B)
{
db[i] = getDistance(B, i);
ckmin(dbmin, db[i]);
if(db[i] < AB)
location[i] = location[B]-db[i], stype[i]=1;
else // outside range: to left or to right?
{
if(db[i] == da[i]-AB) // left
left.push_back({i, location[B]-db[i]});
else
right.push_back({i, location[A]+da[i]});
}
}
std::sort(left.begin(), left.end(), std::greater<appl>());
std::sort(right.begin(), right.end());
{
appl prev(-1,0);
int v;
for(auto n:left)
if(prev.i==-1 ||
(v=getDistance(prev.i, n.i)) == db[prev.i]+db[n.i])
{
prev=n;
location[n.i]=n.x;
stype[n.i]=1;
}
else
{
location[n.i]=prev.x+v;
stype[n.i]=2;
}
}
{
appl prev(-1,0);
int v;
for(auto n:right)
if(prev.i==-1 ||
(v=getDistance(prev.i, n.i)) == db[prev.i]+db[n.i]-2*dbmin)
{
prev=n;
location[n.i]=n.x;
stype[n.i]=2;
}
else
{
location[n.i]=prev.x-v;
stype[n.i]=1;
}
}
//for(int i=0;i<N;++i) printf("%d %d\n", stype[i], location[i]);
}
Compilation message (stderr)
rail.cpp:9:12: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
9 | bool ckmin(auto& a, const auto& b) {return b<a?a=b,1:0;}
| ^~~~
rail.cpp:9:27: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
9 | bool ckmin(auto& a, const auto& b) {return b<a?a=b,1:0;}
| ^~~~
rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:42:23: warning: 'B' may be used uninitialized in this function [-Wmaybe-uninitialized]
42 | db[i] = getDistance(B, 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... |