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 nmax = 5000;
bool fix[nmax + 1];
int v[nmax + 1], tip[nmax + 1];
int mn[nmax + 1];
vector<pair<int, int>> d[nmax + 1];
int val[nmax + 1][nmax + 1];
struct str {
int i, j, x;
str () {}
str (int _i, int _j, int _x) {
i = _i, j = _j, x = _x;
}
};
vector<str> vc;
const int valmax = 2e6 + 5;
static int cnt[valmax + 1];
void findLocation(int N, int first, int location[], int stype[]) {
for (int i = 0; i < N; ++ i)
for (int j = i + 1; j < N; ++ j) {
int x = getDistance(i, j);
val[i][j] = x;
++ cnt[x];
}
for (int i = 1; i <= valmax; ++ i)
cnt[i] += cnt[i - 1];
vc.resize(N * (N - 1) / 2);
for (int i = 0; i < N; ++ i) {
for (int j = i + 1; j < N; ++ j) {
vc[-- cnt[val[i][j]]] = str(i, j, val[i][j]);
}
}
for (auto i : vc) {
d[i.i].push_back({i.x, i.j});
d[i.j].push_back({i.x, i.i});
}
v[0] = first;
tip[0] = 1;
fix[0] = 1;
for (int step = 0; step < N - 1; ++ step) {
int x, y, e = 1 << 30;
x = y = -1;
for (int i = 0; i < N; ++ i) {
if (fix[i] == 1) {
while (mn[i] < N - 1 && fix[d[i][mn[i]].second] == 1)
++ mn[i];
if (mn[i] < N - 1 && d[i][mn[i]].first < e) {
x = i;
y = d[i][mn[i]].second;
e = d[i][mn[i]].first;
}
}
}
if (tip[x] == 1) {
v[y] = v[x] + e;
tip[y] = 2;
} else {
v[y] = v[x] - e;
tip[y] = 1;
}
fix[y] = 1;
}
for (int i = 0; i < N; ++ i) {
location[i] = v[i];
stype[i] = tip[i];
}
}
# | 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... |