# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
297768 | juckter | 철로 (IOI14_rail) | C++14 | 87 ms | 632 KiB |
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 <bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
int di0[MAXN], di1[MAXN];
void findLocation(int N, int first, int location[], int stype[]) {
location[0] = first;
stype[0] = 1;
if(N == 1)
return;
int anchor, gap = 3 * N;
for(int i = 1; i < N; i++) {
di0[i] = getDistance(0, i);
if(di0[i] < gap) {
gap = di0[i];
anchor = i;
}
}
di1[0] = gap;
location[anchor] = first + gap;
stype[anchor] = 2;
for(int i = 1; i < N; i++) {
if(i == anchor)
continue;
di1[i] = getDistance(anchor, i);
}
vector<pair<int, int>> left, right;
for(int i = 1; i < N; i++) {
if(i == anchor)
continue;
if(di0[i] == gap + di1[i]) {
// station is to the left of anchor
if(di1[i] < gap) {
// downward station for sure
location[i] = location[anchor] - di1[i];
stype[i] = 1;
}
else
left.push_back({di1[i], i});
}
else {
// station is to the right of anchor
right.push_back({di0[i], i});
}
}
// Find right
int R = anchor;
for(auto p : right) {
int dis = p.first, sta = p.second;
int ex = getDistance(R, sta);
if(di0[sta] != di0[R] + ex) {
// further upward station
location[sta] = location[0] + di0[sta];
stype[sta] = 2;
sta = R;
}
else {
// downward
location[sta] = location[R] - ex;
stype[sta] = 1;
}
}
// Find left
// Find right
int L = 0;
for(auto p : left) {
int dis = p.first, sta = p.second;
int ex = getDistance(L, sta);
if(di1[sta] != di1[R] + ex) {
// further downward station
location[sta] = location[anchor] - di1[sta];
stype[sta] = 1;
sta = L;
}
else {
// upward
location[sta] = location[R] + ex;
stype[sta] = 2;
}
}
return;
}
Compilation message (stderr)
# | 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... |