#include"rail.h"
#include<iostream>
#include<vector>
#include<algorithm>
typedef long long ll;
using namespace std;
void findLocation(int n,int first,int location[],int stype[]){
location[0]=0;
vector<pair<int,int>>dist0(n-1);
for(int i=0;i<n-1;i++)
dist0[i]={getDistance(0,i+1),i+1};
sort(dist0.begin(),dist0.end());
vector<int>left,right;
stype[0]=1;
for(auto[dist,i]:dist0){
if(right.empty()){
right.push_back(i);
location[i]=dist;
stype[i]=2;
continue;
}
int dist1=getDistance(right[0],i);
if(dist1+dist0[right[0]].first==dist){ // i is on the left side
dist-=2*dist0[right[0]].first;
bool done=false;
for(int j=0;j<(int)left.size()-1;j++){
int a=location[left[j]];
int b=location[left[j+1]];
int nloc=2*a+dist;
if(a<nloc&&nloc<b){
int dist2=getDistance(left[j],i);
if(dist2-a==dist){
done=true;
location[i]=nloc;
stype[i]=2;
}
}
}
if(!done){
left.push_back(i);
location[i]=-dist;
stype[i]=1;
}
}else{ // i is on the right side
bool done=false;
for(int j=1;j<(int)right.size()-1;j++){
int a=location[right[j]];
int b=location[right[j+1]];
int nloc=2*b-dist;
if(a<nloc&&nloc<b){
int dist2=getDistance(right[j+1],i);
if(dist2+b==dist){
done=true;
location[i]=nloc;
stype[i]=1;
}
}
}
if(!done){
right.push_back(i);
location[i]=dist;
stype[i]=2;
}
}
}
for(int i=0;i<n;i++){
location[i]+=first;
//cout<<stype[i]<<" "<<location[i]<<"\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
520 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
520 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
516 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
57 ms |
660 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
58 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |