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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int p[100009], l[100009], dist[5009][5009];
int getDist(int a, int b) {
if (a > b) swap(a, b);
if (dist[a][b] != -1) return dist[a][b];
int ZZ = getDistance(a, b);
dist[a][b] = ZZ;
return ZZ;
}
void findLocation(int N, int first, int location[], int stype[])
{
for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) dist[i][j] = -1; }
// ----------------------------------- 一審 -----------------------------------------
int minx = (1 << 30), minid = 0;
for (int i = 0; i < N; i++) { if (i == 0) continue; int z = getDist(0, i); if (z < minx) { minx = z; minid = i; } }
l[minid] = minx; p[minid] = 2;
l[0] = 0; p[0] = 1;
// ----------------------------------- 二審 -----------------------------------------
vector<pair<int, int>>E1, E2;
for (int i = 0; i < N; i++) {
if (i == 0 || i == minid) continue;
if (getDist(i, minid) < getDist(i, 0)) { l[i] = -10000; E1.push_back(make_pair(getDist(minid, i), i)); }
else { l[i] = 10000; E2.push_back(make_pair(getDist(0, i), i)); }
}
sort(E1.begin(), E1.end());
sort(E2.begin(), E2.end());
// ----------------------------------- 終審 -----------------------------------------
vector<int>Z1;
for (int i = 0; i < E1.size(); i++) {
int pos = E1[i].second; bool OK = false;
for (int j = 0; j < Z1.size(); j++) {
if (getDist(minid, pos) == getDist(minid, Z1[j]) + getDist(Z1[j], pos)) {
p[pos] = 2; l[pos] = l[Z1[j]] + getDist(Z1[j], pos);
OK = true;
break;
}
}
if (OK == false) {
p[pos] = 1; l[pos] = minx - getDist(minid, pos); Z1.push_back(pos);
}
}
vector<int>Z2;
for (int i = 0; i < E2.size(); i++) {
int pos = E2[i].second; bool OK = false;
for (int j = 0; j < Z2.size(); j++) {
if (getDist(0, pos) == getDist(0, Z2[j]) + getDist(Z2[j], pos)) {
p[pos] = 1; l[pos] = l[Z2[j]] - getDist(Z2[j], pos);
OK = true;
break;
}
}
if (OK == false) {
p[pos] = 2; l[pos] = getDist(0, pos); Z2.push_back(pos);
}
}
for (int i = 0; i < N; i++) location[i] = l[i] + first;
for (int i = 0; i < N; i++) stype[i] = p[i];
return;
}
Compilation message (stderr)
rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:40:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < E1.size(); i++) {
~~^~~~~~~~~~~
rail.cpp:42:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < Z1.size(); j++) {
~~^~~~~~~~~~~
rail.cpp:54:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < E2.size(); i++) {
~~^~~~~~~~~~~
rail.cpp:56:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < Z2.size(); j++) {
~~^~~~~~~~~~~
# | 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... |