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;
const int N = 5000;
int dist[N], ord[N];
vector<int> adj[N];
void findLocation(int n, int first, int location[], int stype[]){
for(int i = 1; i < n; i++)
dist[i] = getDistance(0, i);
for(int i = 0; i < n; i++)
ord[i] = i;
sort(ord, ord + n, [&](const int &a, const int &b){
return dist[a] < dist[b];
});
map<int, int> m;
int a = 0, b = ord[1];
location[a] = first;
location[b] = first + dist[b];
stype[a] = 1;
stype[b] = 2;
m[location[a]] = stype[a];
m[location[b]] = stype[b];
for(int i = 2; i < n; i++){
int u = ord[i];
int dA = getDistance(a, u);
int dB = getDistance(b, u);
int mid = (location[a] + dA + location[b] - dB) / 2;
if (m[mid] == 1 || (m[mid] == 0 && location[0] < mid)){
location[u] = location[a] + dA;
stype[u] = 2;
if (location[u] > location[b])
b = u;
} else {
location[u] = location[b] - dB;
stype[u] = 1;
if (location[u] < location[a])
a = u;
}
m[location[u]] = stype[u];
}
}
# | 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... |