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 rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int INF=1e9+7;
void findLocation(int n, int first, int location[], int stype[]) {
location[0]=first;
rep(i, n) stype[i]=1;
if(n==1) return;
vector<int>A(n);
for(int i=1; i<n; ++i) A[i]=getDistance(0, i);
pair<int,int>mi={A[1], 1};
for(int i=1; i<n; ++i) mi=min(mi, {A[i], i});
int x=mi.nd;
stype[x]=2;
location[x]=location[0]+mi.st;
vector<int>B(n);
rep(i, n) if(i!=x) B[i]=getDistance(x, i);
vector<pair<int,int>>lewo, prawo;
for(int i=1; i<n; ++i) if(i!=x) {
if(max(A[i], B[i])<2*mi.st) location[i]=location[x]-B[i];
else if(A[i]<B[i]) prawo.pb({A[i], i});
else lewo.pb({B[i], i});
}
sort(all(prawo));
sort(all(lewo));
int lst=x;
for(auto i : prawo) {
int a=getDistance(lst, i.nd);
if(a==i.st-A[lst]) location[i.nd]=location[lst]-a;
else {
location[i.nd]=location[0]+i.st;
lst=i.nd;
stype[i.nd]=2;
}
}
lst=0;
for(auto i : lewo) {
int a=getDistance(lst, i.nd);
if(a==i.st-B[lst]) {
location[i.nd]=location[lst]+a;
stype[i.nd]=2;
} else {
location[i.nd]=location[x]-i.st;
lst=i.nd;
}
}
}
# | 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... |