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 fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;}
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int get(int x,int y) {
if (x == y)
return 0;
return getDistance(x,y);
}
void findLocation(int N, int first, int location[], int stype[]) {
int n = N;
vi d0(n),d1(n);
for (int i = 0;i < n;++i)
stype[i] = -1;
for (int i = 0;i < n;++i)
d0[i] = get(0,i);
const int a = 0;
const int b = min_element(d0.begin() + 1,d0.end()) - d0.begin();
location[a] = first;
stype[a] = 1;
location[b] = first + d0[b];
stype[b] = 2;
for (int i = 0;i < n;++i)
d1[i] = get(b,i);
vi lf,rg;
for (int i = 0;i < n;++i)
if (i != a && i != b) {
if (d0[i] == d0[b] + d1[i]) {
if (d1[i] < d0[b]) {
location[i] = location[b] - d1[i];
stype[i] = 1;
} else {
lf.pb(i);
}
} else {
rg.pb(i);
}
}
sort(all(lf),[&](int x,int y) {
return d1[x] < d1[y];
});
sort(all(rg),[&](int x,int y) {
return d0[x] < d0[y];
});
int lst = a;
map < int , int > was;
for (int i = 0;i < n;++i)
if (stype[i] > 0)
was[location[i]] = stype[i];
for (auto it : lf) {
const int ds = get(lst,it);
int ps = location[lst] + (location[b] - location[lst] + ds - d1[it]) / 2;
if (was.count(ps) && was[ps] == 1) {
location[it] = location[lst] + ds;
stype[it] = 2;
was[location[it]] = 2;
} else {
location[it] = location[b] - d1[it];
stype[it] = 1;
lst = it;
was[location[it]] = 1;
}
}
lst = b;
for (auto it : rg) {
const int ds = get(lst,it);
int ps = location[lst] - (location[lst] - location[a] + ds - d0[it]) / 2;
if (was.count(ps) && was[ps] == 2) {
location[it] = location[lst] - ds;
stype[it] = 1;
was[location[it]] = 1;
} else {
location[it] = location[a] + d0[it];
stype[it] = 2;
lst = it;
was[location[it]] = 2;
}
}
}
# | 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... |