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>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll inf = 1e18;
const int i_inf = 1e9;
const ll mod = 1e9+7;
mt19937 _rand(time(NULL));
const int mxn = 5005;
#include "rail.h"
int d0[mxn];
int d1[mxn];
/*
int getDistance(int i, int j){
cout<<"? "<<i<<' '<<j<<endl;
int ret;
cin >> ret;
return ret;
}
*/
int s[mxn];
int l[mxn];
vector<int> L;
vector<int> R;
void findLocation(int N, int first, int location[], int stype[]){
location[0] = first;
stype[0] = 1;
if(N == 1){
return;
}
fr(i, 1, N){
d0[i] = getDistance(0, i);
}
int minD = 1e9;
int p = 0;
fr(i, 1, N){
if(d0[i] < minD){
minD = d0[i];
p = i;
}
}
int pivot = p;
d1[0] = d0[p];
fr(i, 1, N){
if(i == p) continue;
d1[i] = getDistance(p, i);
}
fr(i, 0, N){
if(i == p || i == 0) continue;
if(d0[i] == d1[i] + d0[p]){
L.pb(i);
}
else{
R.pb(i);
}
}
sort(all(R), [](const int &i, const int &j){
return d0[i] < d0[j];
});
location[p] = location[0] + d0[p];
stype[p] = 2;
if(N == 2){
return;
}
for(auto u : R){
int w = getDistance(pivot, u);
if(d0[u] == d0[pivot] + w){
location[u] = location[pivot] - w;
stype[u] = 1;
}
else{
location[u] = location[0] + d0[u];
stype[u] = 2;
pivot = u;
}
}
int p2;
minD = 1e9;
fr(i, 0, N){
if(i == p) continue;
if(d1[i] < minD){
minD = d1[i];
p2 = i;
}
}
L.pb(0);
sort(all(L), [](const int &i, const int &j){
return d1[i] < d1[j];
});
int pivot2 = p2;
location[p2] = location[p] - d1[p2];
stype[p2] = 1;
for(auto u : L){
if(u == p2) continue;
int w = getDistance(pivot2, u);
if(d1[u] == d1[pivot2] + w){
location[u] = location[pivot2] + w;
stype[u] = 2;
}
else{
location[u] = location[p] - d1[u];
stype[u] = 1;
pivot2 = u;
}
}
}
/*
int main(){
int loc[mxn];
int sty[mxn];
findLocation(4, 2, loc, sty);
fr(i, 0, 4){
cout<<loc[i]<<' ';
}
cout<<endl;
fr(i, 0, 4){
cout<<sty[i]<<' ';
}
cout<<endl;
}
*/
Compilation message (stderr)
rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:135:11: warning: 'p2' may be used uninitialized in this function [-Wmaybe-uninitialized]
135 | location[p2] = location[p] - d1[p2];
| ^~
# | 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... |