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 <bits/stdc++.h>
#include "rail.h"
#define gd getDistance
#define eb emplace_back
using namespace std;
void findLocation(int N, int first, int L[], int T[]) {
T[0]=1;
L[0]=0;
vector<int> D(N), S;
int mn=(1e9), mi;
for (int i=1; i<N; i++) {
D[i]=gd(0, i);
if (mn>D[i]) mn=D[i], mi=i;
}
T[mi]=2;
L[mi]=mn;
int l=0, r=mi;
for (int i=0; i<N; i++) if (i!=l&&i!=r) S.eb(i);
sort(S.begin(), S.end(), [&](int x, int y) { return D[x]<D[y]; });
for (auto &i:S) {
int d1=gd(l, i), d2=gd(r, i);
if (d1==d2+L[r]-L[l]) {
L[i]=L[r]-d2;
T[i]=1;
if (L[i]<L[l]) l=i;
}
else if (d1+L[r]-L[l]==d2) {
L[i]=L[l]+d1;
T[i]=2;
if (L[i]>L[r]) i=r;
}
else assert(false);
}
for (int i=0; i<N; i++) L[i]=L[i]+first;
}
Compilation message (stderr)
rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:18:4: warning: 'mi' may be used uninitialized in this function [-Wmaybe-uninitialized]
18 | T[mi]=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... |