# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
785283 | Hanksburger | Rail (IOI14_rail) | C++17 | 52 ms | 4436 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;
int x[1000005], res1[5005], res2[5005];
vector<pair<int, int> > v, w;
void findLocation(int n, int k, int a[], int b[])
{
a[0]=k;
b[0]=1;
x[a[0]]=b[0];
if (n==1)
return;
int ind, mn=1e9, cur=0;
for (int i=1; i<n; i++)
{
res1[i]=getDistance(0, i);
if (mn>res1[i])
{
mn=res1[i];
ind=i;
}
}
res2[0]=res1[ind];
a[ind]=a[0]+res1[ind];
b[ind]=2;
x[a[ind]]=b[ind];
for (int i=1; i<n; i++)
{
if (i==ind)
continue;
res2[i]=getDistance(ind, i);
if (res1[i]==res1[ind]+res2[i])
{
if (res2[i]<res1[ind])
{
a[i]=a[ind]-res2[i];
b[i]=1;
x[a[i]]=b[i];
}
else
v.push_back({res2[i], i});
}
else
w.push_back({res1[i], i});
}
sort(v.begin(), v.end());
sort(w.begin(), w.end());
for (int i=0; i<v.size(); i++)
{
int u=v[i].second;
int res=getDistance(cur, u);
if (x[a[cur]+(res2[cur]+res-res2[u])/2]==1)
{
a[u]=a[cur]+res;
b[u]=2;
}
else
{
a[u]=a[ind]-res2[u];
b[u]=1;
cur=u;
}
x[a[u]]=b[u];
}
cur=ind;
for (int i=0; i<w.size(); i++)
{
int u=w[i].second;
int res=getDistance(cur, u);
if (x[a[cur]-(res1[cur]+res-res1[u])/2]==2)
{
a[u]=a[cur]-res;
b[u]=1;
}
else
{
a[u]=a[0]+res1[u];
b[u]=2;
cur=u;
}
x[a[u]]=b[u];
}
}
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... |