이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rail.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 5010;
int from_0[N];
int from_1[N];
vector<pii> lefty;
vector<pii> wright;
int n;
enum {
C = 1,
D = 2,
};
void findLocation(int _N, int first, int location[], int stype[])
{
n = _N;
int mn = 1;
Loop (i,1,n) {
from_0[i] = getDistance(0, i);
if (from_0[i] < from_0[mn])
mn = i;
}
int X, Y = 1e9+10;
Loop (i,0,n) {
if (i == mn)
continue;
from_1[i] = getDistance(mn, i);
if (from_1[i] < Y)
Y = from_1[i];
}
X = from_0[mn] - Y;
from_0[0] = 2*(X+Y);
cerr << "mn = " << mn << '\n';
Loop (i,0,n) {
if (i == mn)
continue;
if (from_0[i] - from_1[i] == X-Y)
wright.push_back({from_1[i], i});
else if (from_0[i] - from_1[i] == X+Y)
lefty.push_back({from_1[i], i});
else
assert(false);
}
sort(lefty.begin(), lefty.end());
sort(wright.begin(), wright.end());
assert(lefty.size());
int rD = mn, rC = lefty.front().second;
int lD = mn, lC = lefty.front().second;
lefty.erase(lefty.begin());
location[mn] = first + from_0[mn];
stype[mn] = D;
location[lC] = location[mn] - from_1[lC];
stype[lC] = C;
for (auto [_, i] : wright) {
int disr = getDistance(rD, i);
int locD = location[0] + from_0[i];
cerr << location[rD] + locD - 2*location[rC] << '\n';
if (disr == location[rD] + locD - 2*location[rC]) {
stype[i] = D;
location[i] = locD;
rD = i;
} else {
stype[i] = C;
location[i] = location[rD] - disr;
if (location[i] > location[rC])
rC = i;
}
}
for (auto [_, i] : lefty) {
int disl = getDistance(lC, i);
int locC = location[mn] - from_1[i];
if (disl == 2*location[lD] - location[lC] - locC) {
stype[i] = C;
location[i] = locC;
lC = i;
} else {
stype[i] = D;
location[i] = location[lC] + disl;
if (location[i] < location[lD])
lD = 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... |