이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rail.h"
#include<bits/stdc++.h>
using namespace std;
int lst[1000100];
int dist[5000];
void findLocation(int N, int first, int location[], int stype[])
{
location[0]=first;
stype[0]=1;
lst[first]=0;
int n=N;
if(n==1)return;
#define loc location
#define ty stype
for(int i=1;i<n;i++){
dist[i]=getDistance(0,i);
}
int pp[n];
for(int i=0;i<n;i++){
pp[i]=i;
}
sort(pp+1,pp+n,[&](int i,int j)->bool {
return dist[i]<dist[j];
});
int cl=pp[1];
lst[location[cl]=first+dist[cl]]=cl;
stype[cl]=2;
int l=0,r=cl;
for(int i=2;i<n;i++){
int p=pp[i];
int k=getDistance(cl,p);
if(dist[p]==dist[cl]+k){
if(k<dist[cl]){
ty[p]=1;
lst[loc[p]=loc[cl]-k]=p;
}else if(l==0){
l=p;
ty[p]=1;
lst[loc[p]=loc[cl]-k]=p;
}else{
int dd=getDistance(l,p);
int possible=loc[l]+dd;
int x=(k-(loc[cl]-possible))/2;
int guy=lst[possible-x];
if(ty[guy]==1){
ty[p]=2;
lst[loc[p]=possible]=p;
}else{
ty[p]=1;
lst[loc[p]=loc[cl]-k]=p;
l=p;
}
}
}else{
k=dist[p];
if(r==cl){
r=p;
ty[p]=2;
lst[loc[p]=loc[0]+k]=p;
}else{
int dd=getDistance(r,p);
int possible=loc[r]-dd;
int x=(k-(possible-loc[0]))/2;
int guy=lst[possible+x];
if(ty[guy]==2){
ty[p]=1;
lst[loc[p]=possible]=p;
}else{
ty[p]=2;
lst[loc[p]=loc[0]+k]=p;
r=p;
}
}
}
}
}
# | 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... |