#include "rail.h"
#include<algorithm>
using namespace std;
void findLocation(int n, int frst, int loc[], int type[]){
int i, st, dr, dist1, dist2, x, j, minim, p;
pair<int, int> v[5005];
loc[0] = frst;
type[0] = 1;
for(i = 1; i < n; i++){
v[i].second = i;
v[i].first = getDistance(0, i);
}
sort(v + 1, v + n);
st = 0;
dr = v[1].second;
loc[dr] = v[1].first + loc[0];
type[dr] = 2;
for(i = 2; i < n; i++){
x = v[i].second;
dist1 = getDistance(st, x);
dist2 = getDistance(dr, x);
p = loc[st] + dist1;
if(x == 966){
int abc = 0;
}
if(p < loc[0]){
minim = 10000000;
for(j = 0; j < n; j++){
if(type[j] == 1){
if(loc[j] < p && loc[j] < loc[dr]){
minim = min(minim, p - loc[j] + loc[dr] - loc[j]);
}
}
}
if(dist2 == minim){
type[x] = 2;
loc[x] = p;
if(loc[x] > loc[dr]){
dr = x;
}
}
else{
type[x] = 1;
loc[x] = loc[dr] - dist2;
if(loc[x] < loc[st]){
st = x;
}
}
}
else{
p = loc[dr] - dist2;
if(p > loc[0]){
minim = 10000000;
for(j = 0; j < n; j++){
if(type[j] == 2){
if(loc[j] > p && loc[j] > loc[st]){
minim = min(minim, loc[j] - p + loc[j] - loc[st]);
}
}
}
if(minim == dist1){
type[x] = 1;
loc[x] = p;
if(loc[x] < loc[st]){
st = x;
}
}
else{
type[x] = 2;
loc[x] = loc[st] + dist1;
if(loc[x] > loc[dr]){
dr = x;
}
}
}
else{
p = loc[dr] - dist2;
if(v[i].first != v[1].first + loc[ v[1].second ] - p){
type[x] = 2;
loc[x] = loc[st] + dist1;
if(loc[x] > loc[dr]){
dr = x;
}
}
else{
type[x] = 1;
loc[x] = loc[dr] - dist2;
if(loc[x] < loc[st]){
st = x;
}
}
}
}
}
int abc = 0;
}
Compilation message
rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:25:17: warning: unused variable 'abc' [-Wunused-variable]
25 | int abc = 0;
| ^~~
rail.cpp:96:9: warning: unused variable 'abc' [-Wunused-variable]
96 | int abc = 0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
135 ms |
504 KB |
Output is correct |
2 |
Correct |
135 ms |
504 KB |
Output is correct |
3 |
Correct |
143 ms |
504 KB |
Output is correct |
4 |
Correct |
138 ms |
504 KB |
Output is correct |
5 |
Correct |
137 ms |
504 KB |
Output is correct |
6 |
Correct |
133 ms |
556 KB |
Output is correct |
7 |
Correct |
132 ms |
504 KB |
Output is correct |
8 |
Correct |
137 ms |
504 KB |
Output is correct |
9 |
Correct |
139 ms |
504 KB |
Output is correct |
10 |
Correct |
143 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
135 ms |
492 KB |
Output is correct |
2 |
Correct |
134 ms |
500 KB |
Output is correct |
3 |
Correct |
149 ms |
504 KB |
Output is correct |
4 |
Correct |
141 ms |
504 KB |
Output is correct |
5 |
Correct |
139 ms |
496 KB |
Output is correct |
6 |
Correct |
133 ms |
632 KB |
Output is correct |
7 |
Correct |
131 ms |
504 KB |
Output is correct |
8 |
Correct |
143 ms |
504 KB |
Output is correct |
9 |
Correct |
140 ms |
504 KB |
Output is correct |
10 |
Correct |
135 ms |
504 KB |
Output is correct |
11 |
Correct |
136 ms |
504 KB |
Output is correct |
12 |
Correct |
134 ms |
628 KB |
Output is correct |
13 |
Correct |
136 ms |
504 KB |
Output is correct |
14 |
Correct |
132 ms |
504 KB |
Output is correct |
15 |
Correct |
158 ms |
504 KB |
Output is correct |
16 |
Correct |
134 ms |
504 KB |
Output is correct |
17 |
Correct |
129 ms |
632 KB |
Output is correct |
18 |
Correct |
131 ms |
588 KB |
Output is correct |
19 |
Correct |
137 ms |
632 KB |
Output is correct |
20 |
Correct |
130 ms |
504 KB |
Output is correct |