# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
48592 | gs12117 | Rail (IOI14_rail) | C++11 | 215 ms | 972 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<vector>
#include<algorithm>
#include "rail.h"
int n;
int distz[5010];
int distf[5010];
int side[5010];
int vchk[5010];
struct stn {
int loc, val;
bool operator<(const stn&r)const {
return val < r.val;
}
};
void findLocation(int N, int first, int location[], int stype[])
{
if (n == 1) {
location[0] = first;
stype[0] = 1;
return;
}
n = N;
distz[0] = 0;
int f = -1;
for (int i = 1; i < n; i++) {
distz[i] = getDistance(0, i);
if (f == -1 || distz[i] < distz[f])f = i;
}
int rdf = distz[f];
distf[f] = 0;
distf[0] = rdf;
int g = 0;
for (int i = 1; i < n; i++) {
if (i == f)continue;
distf[i] = getDistance(i, f);
if (distz[i] == distf[i] + rdf)side[i] = 1;
else side[i] = 0;
if (distf[i] < distf[g])g = i;
}
side[0] = 1;
int df = distf[g];
location[f] = first + rdf;
location[g] = location[f] - df;
stype[f] = 2;
stype[g] = 1;
for (int i = 0; i < n; i++) {
vchk[i] = 0;
}
vchk[f] = 1;
vchk[g] = 1;
std::vector<stn> l, r;
for (int i = 0; i < n; i++) {
if (i == f || i == g)continue;
stn t;
t.loc = i;
t.val = distf[i];
if (side[i] == 1)l.push_back(t);
else r.push_back(t);
}
std::sort(l.begin(), l.end());
std::sort(r.begin(), r.end());
int pd = g;
for (int i = 0; i < l.size(); i++) {
int x = l[i].loc;
int d = l[i].val;
int pr = getDistance(pd, x);
int pl = location[f] - location[pd];
int p = d - pl;
int q = (pr - p) / 2;
int y = location[f] - (pl - q);
int flag = 0;
for (int j = 0; j < n; j++) {
if (vchk[j] == 1 && location[j] == y&&stype[j] == 1) {
flag = 1;
break;
}
}
if (flag == 1) {
stype[x] = 2;
location[x] = location[pd] + pr;
vchk[x] = 1;
}
else {
stype[x] = 1;
location[x] = location[f] - pl - p;
vchk[x] = 1;
pd = x;
}
}
pd = f;
for (int i = 0; i < r.size(); i++) {
int x = r[i].loc;
int d = r[i].val;
int pr = getDistance(pd, x);
int pl = location[pd] - location[g];
int p = d - df - pl;
int q = (pr - p) / 2;
int y = location[g] + (pl - q);
int flag = 0;
for (int j = 0; j < n; j++) {
if (vchk[j] == 1 && location[j] == y&&stype[j] == 2) {
flag = 1;
break;
}
}
if (flag == 1) {
stype[x] = 1;
location[x] = location[pd] - pr;
vchk[x] = 1;
}
else {
stype[x] = 2;
location[x] = location[g] + pl + p;
vchk[x] = 1;
pd = x;
}
}
}
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... |