# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
588193 | AlperenT | Rail (IOI14_rail) | C++17 | 66 ms | 512 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 <bits/stdc++.h>
#include "rail.h"
using namespace std;
void findLocation(int n, int A, int location[], int stype[]){
location[0] = A;
stype[0] = 1;
A = 0;
if(n == 1) return;
int distA[n] = {};
int distB[n] = {};
for(int i = 1; i < n; i++){
distA[i] = getDistance(A, i);
}
int B = min_element(distA + 1, distA + n) - distA;
location[B] = location[A] + distA[B];
stype[B] = 2;
vector<pair<int, int>> lft, rght;
for(int i = 1; i < n; i++){
if(i != B){
distB[i] = getDistance(B, i);
if(distA[i] == distA[B] + distB[i]) lft.push_back({distB[i], i});
else rght.push_back({distA[i], i});
}
}
sort(lft.begin(), lft.end());
if(!lft.empty()){
int C = lft.front().second;
location[C] = location[B] - distB[C];
stype[C] = 1;
for(int i = 1; i < lft.size(); i++){
int X = lft[i].second;
int dist = getDistance(C, X);
if(distB[X] == distB[C] + dist){
location[X] = location[C] + dist;
stype[X] = 2;
}
else{
location[X] = location[B] - distB[X];
stype[X] = 1;
C = X;
}
}
}
sort(rght.begin(), rght.end());
if(!rght.empty()){
int D = rght.front().second;
location[D] = location[A] + distA[D];
stype[D] = 2;
for(int i = 1; i < rght.size(); i++){
int X = rght[i].second;
int dist = getDistance(D, X);
if(distA[X] == distA[D] + dist){
location[X] = location[D] - dist;
stype[X] = 1;
}
else{
location[X] = location[A] + distA[X];
stype[X] = 2;
D = 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... |