이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); it++)
typedef long long ll;
typedef pair < int, int > ii;
const int inf = 1e9 + 333;
const ll linf = 1e18 + inf;
#include "rail.h"
const int N = 5000 + 5;
ii a[N];
void findLocation(int n, int first, int location[], int stype[]) {
for(int i = 1; i < n; i++) {
a[i].first = getDistance(0, i);
a[i].second = i;
}
sort(a + 1, a + n);
int second = a[1].second;
location[0] = first;
stype[0] = 1;
location[second] = first + a[1].first;
stype[second] = 2;
int L = 0, R = second;
set < int > sd, su;
sd.insert(location[L]);
su.insert(location[R]);
for(int it = 2; it < n; it++) {
int dist = a[it].first;
int i = a[it].second;
int distSecond = getDistance(second, i);
if(dist == distSecond + a[1].first and location[second] - distSecond < first) {
int distL = getDistance(L, i);
int p = location[L] + distL;
type(sd) it = sd.lower_bound(p);
it--;
int bef = *it;
if(location[second] - bef + p - bef == distSecond) {
location[i] = p;
stype[i] = 2;
}
else {
location[i] = location[second] - distSecond;
stype[i] = 1;
sd.insert(location[i]);
L = i;
}
}
else {
int distR = getDistance(R, i);
int p = location[R] - distR;
type(su) it = su.upper_bound(p);
int aft = *it;
if(aft - first + aft - p == dist) {
location[i] = p;
stype[i] = 1;
}
else {
location[i] = first + dist;
stype[i] = 2;
su.insert(location[i]);
R = 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... |