#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];
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
432 KB |
Output is correct |
5 |
Correct |
1 ms |
424 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
424 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
428 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
416 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
816 KB |
Output is correct |
2 |
Correct |
84 ms |
796 KB |
Output is correct |
3 |
Correct |
84 ms |
836 KB |
Output is correct |
4 |
Correct |
84 ms |
836 KB |
Output is correct |
5 |
Correct |
88 ms |
804 KB |
Output is correct |
6 |
Correct |
87 ms |
836 KB |
Output is correct |
7 |
Correct |
86 ms |
808 KB |
Output is correct |
8 |
Correct |
90 ms |
824 KB |
Output is correct |
9 |
Correct |
86 ms |
820 KB |
Output is correct |
10 |
Correct |
87 ms |
812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
804 KB |
Output is correct |
2 |
Correct |
85 ms |
824 KB |
Output is correct |
3 |
Correct |
84 ms |
836 KB |
Output is correct |
4 |
Correct |
84 ms |
836 KB |
Output is correct |
5 |
Correct |
85 ms |
816 KB |
Output is correct |
6 |
Correct |
92 ms |
760 KB |
Output is correct |
7 |
Correct |
87 ms |
800 KB |
Output is correct |
8 |
Correct |
84 ms |
804 KB |
Output is correct |
9 |
Correct |
88 ms |
756 KB |
Output is correct |
10 |
Correct |
85 ms |
812 KB |
Output is correct |
11 |
Correct |
89 ms |
804 KB |
Output is correct |
12 |
Correct |
86 ms |
836 KB |
Output is correct |
13 |
Correct |
85 ms |
800 KB |
Output is correct |
14 |
Correct |
86 ms |
820 KB |
Output is correct |
15 |
Correct |
87 ms |
836 KB |
Output is correct |
16 |
Correct |
88 ms |
816 KB |
Output is correct |
17 |
Correct |
85 ms |
800 KB |
Output is correct |
18 |
Correct |
86 ms |
836 KB |
Output is correct |
19 |
Correct |
85 ms |
836 KB |
Output is correct |
20 |
Correct |
85 ms |
824 KB |
Output is correct |