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>
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)/2)
#define all(x) x.begin(),x.end()
#define inf 1000000000
#define MOD 1000000007
#define M 1000000
#define LOG 20
#define KOK 300
#define EPS 0.0000001
using namespace std;
void findLocation(int N, int first, int location[], int stype[]) {
location[0]=first;
stype[0]=1;
vector<ii> a(N);
a[0]={0,0};
for(int i=1;i<N;i++) {
a[i]={getDistance(0,i),i};
}
sort(a.begin(),a.end());
location[a[1].nd]=first+a[1].st;
stype[a[1].nd]=2;
for(int i=0;i<N;i++) cerr<<a[i].nd<<" ";
cerr<<"\n\n";
vector<int> rails;
rails.pb(0);
rails.pb(a[1].nd);
for(int i=2;i<N;i++) {
int dsecond=getDistance(a[1].nd,a[i].nd);
if(dsecond<a[i].st) {
// on the left
int ds3=getDistance(rails[0],a[i].nd);
int uppos=location[rails[0]]+ds3;
int ne=-1;
for(int j=0;j<sz(rails);j++) {
if(location[rails[j]]<uppos && stype[rails[j]]==1) ne=rails[j];
}
if(uppos<location[0] && ~ne && dsecond==location[a[1].nd]-location[ne]+uppos-location[ne]) {
location[a[i].nd]=uppos;
stype[a[i].nd]=2;
}
else {
location[a[i].nd]=location[a[1].nd]-dsecond;
stype[a[i].nd]=1;
}
}
else {
// on the right
int ds3=getDistance(rails.back(),a[i].nd);
int dopos=location[rails.back()]-ds3;
int ne=-1;
for(int j=sz(rails)-1;j>=0;j--) {
if(location[rails[j]]>dopos && stype[rails[j]]==2) ne=rails[j];
}
if(dopos>location[0] && ~ne && a[i].st==location[ne]-dopos+location[ne]-first) {
location[a[i].nd]=dopos;
stype[a[i].nd]=1;
}
else {
location[a[i].nd]=location[a[0].nd]+a[i].st;
stype[a[i].nd]=2;
}
}
if(location[a[i].nd]<location[rails[0]]) rails.insert(rails.begin(),a[i].nd);
else {
for(int j=sz(rails)-1;j>=0;j--) {
if(location[a[i].nd]>location[rails[j]]) {
rails.insert(rails.begin()+j+1,a[i].nd);
break ;
}
}
}
}
}
# | 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... |