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 ff first
#define ss second
int d[5005][3];
vector<pair<int, int> > rh, lh;
int lo[5005], st[5005];
void solve(int con, int flip, vector<pair<int, int> >& v){
sort(v.begin(), v.end());
int r = -1;
for(auto& x : v){
if(r == -1 || getDistance(r, x.ss) != x.ff - lo[r]){
lo[r = x.ss] = x.ff;
st[r] = 1;
} else {
lo[x.ss] = lo[r] - (x.ff - lo[r]);
st[r] = -1;
}
}
for(auto& x : v){
st[x.ss] *= flip;
lo[x.ss] = con + flip * lo[x.ss];
}
}
void findLocation(int N, int first, int location[], int stype[]){
int le, ri;
int n = N;
le = 0;
int tt = 2000000;
for(int i = 0; i < n; ++i){
if(le == i)
continue;
d[i][0] = getDistance(le, i);
if(d[i][0] < tt){
ri = i;
tt = d[i][0];
}
}
tt = 2000000;
for(int i = 0; i < n; ++i){
if(ri == i) continue;
d[i][1] = getDistance(ri, i);
if(d[i][1] < tt){
le = i;
tt = d[i][1];
}
}
cerr<<'\n';
lo[ri] = first + d[ri][0];
st[ri] = 1;
lo[le] = lo[ri] - d[le][1];
st[le] = -1;
for(int i = 0; i < n; ++i){
if(le == i || ri == i) continue;
if(d[i][0] == d[i][1] + d[ri][0]){
rh.push_back({d[i][1], i});
} else {
d[i][1] = d[i][0] - (d[ri][0] - d[le][2]);
lh.push_back({d[i][0], i});
}
}
solve(lo[le], 1, lh);
solve(lo[ri], -1, rh);
for(int i = 0; i < n; ++i){
location[i] = lo[i];
stype[i] = (st[i] == 1 ? 2 : 1);
}
}
Compilation message (stderr)
rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:54:26: warning: 'ri' may be used uninitialized in this function [-Wmaybe-uninitialized]
54 | lo[ri] = first + d[ri][0];
| ~~~~~~~^
# | 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... |