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>
using namespace std;
int getDistance(int i, int j);//{
// cout << i << ' ' << j << '\n';
// int r;
// cin >> r;
// return r;
// }
void findLocation(int n, int first, int location[], int stype[]){
location[0] = first;
stype[0] = 1;
if(n == 1) return;
int d0[n], o[n], d1[n], o1[n], ind = 1;
d0[0] = 0;
for(int i = 1;i < n;i++) {
d0[i] = getDistance(0, i);
o[i-1] = i;
}
sort(o, o+n-1, [&d0](int a, int b){
return d0[a] < d0[b];
});
int s = o[0];
stype[s] = 2;
location[s] = first+d0[s];
d1[0] = d0[s];
o1[0] = 0;
d1[s] = 0;
for(int i = 1;i < n;i++){
if(i == s) continue;
o1[ind++] = i;
d1[i] = getDistance(s, i);
}
sort(o1, o1+ind, [&d1](int a, int b){return d1[a] < d1[b];});
int l = o1[0], l2 = s;
int locl = location[s]-d1[l];
for(int z = 1;z < n-1;z++){
int i = o[z];
if(d0[i] == d0[s]+d1[i]) continue;
int g = getDistance(l2, i);
if(g == location[l2]-locl+first+d0[i]-locl){
l2 = i;
location[i] = first+d0[i];
stype[i] = 2;
} else {
stype[i] = 1;
location[i] = location[l2]-g;
if(location[i] > locl){
locl = location[i];
l = i;
}
}
}
l = s;l2 = -1;
first = location[s];
locl = location[s];
for(int z = 0;z < ind;z++){
int i = o1[z];
if(!i){
l2 = i;
continue;
}
if(d0[i] < d0[s]+d1[i]) continue;
if(l2 == -1){
stype[i] = 1;
location[i] = first-d1[i];
l2 = i;
continue;
}
int g = getDistance(l2, i);
if(g == location[l]-location[l2]+location[l]-first+d1[i]){
l2 = i;
location[i] = first-d1[i];
stype[i] = 1;
} else {
stype[i] = 2;
location[i] = location[l2]+g;
if(location[i] < locl){
locl = location[i];
l = i;
}
}
}
}
// int main(){
// int loc[8], typ[8];
// findLocation(8, 4, loc, typ);
// }
# | 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... |