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 <algorithm>
#include <set>
using namespace std;
#define MAX_N 5005
struct FIRST{
int dis;
int p;
}First[MAX_N];
bool operator<(FIRST X, FIRST Y) {
return X.dis < Y.dis;
}
set<int> C, D;
set<int>::iterator it;
void findLocation(int N, int first, int location[], int stype[])
{
for(int i=1; i<N; i++) {
First[i].dis = getDistance(0, i);
First[i].p = i;
}
sort(First+1, First+N);
stype[0] = 1;
location[0] = first;
int second = First[1].p;
stype[second] = 2;
location[second] = first + First[1].dis;
int leftC = 0, rightD = second;
C.insert(location[0]);
D.insert(location[second]);
for(int i=2; i<N; i++) {
int nowp = First[i].p;
int Second = getDistance(second, nowp);
if(First[i].dis == Second + First[1].dis && location[second] - Second < location[0]) {
//left;
int DisC = getDistance(leftC, nowp);
int positionD = location[leftC] + DisC;
it = C.lower_bound(positionD); it--;
int maxC = *it;
if(location[second] - maxC + positionD - maxC == Second) {
stype[nowp] = 2;
location[nowp] = positionD;
}else{
stype[nowp] = 1;
location[nowp] = location[second] - Second;
leftC = nowp;
C.insert(location[nowp]);
}
}else{
//right;
int DisD = getDistance(rightD, nowp);
int positionC = location[rightD] - DisD;
it = D.upper_bound(positionC);
int minD = *it;
if(minD - location[0] + minD - positionC == First[i].dis) {
stype[nowp] = 1;
location[nowp] = positionC;
}else{
stype[nowp] = 2;
location[nowp] = location[0] + First[i].dis;
rightD = nowp;
D.insert(location[nowp]);
}
}
}
// for(int i=0; i<N; i++) printf("[%d %d]\n", stype[i], location[i]);
}
# | 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... |