#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#include "rail.h"
void findLocation(int N, int first, int location[], int stype[]) {
auto fix = [&](int i, int pos, int type) {
location[i] = pos;
stype[i] = type;
};
REP(i, N) fix(i, -1, -1);
fix(0, first, 1);
vector<pair<int, int>> stations;
FOR(i, 1, N - 1)
stations.emplace_back(getDistance(0, i), i);
sort(stations.begin(), stations.end());
int L = 0, R = stations[0].second;
fix(R, first + stations[0].first, 2);
stations.erase(stations.begin());
for(auto &[d, i] : stations) {
int a = getDistance(L, i);
int b = getDistance(R, i);
{ // [)]
bool ok = false;
int pos = location[L] + a;
REP(j, N) {
if(stype[j] == 1) {
if(location[R] + pos - 2 * location[j] == b)
ok = true;
}
}
if(ok) {
fix(i, pos, 2);
if(location[R] < pos) R = i;
continue;
}
}
{ // (
int pos = location[R] - b;
bool ok = false;
REP(j, N) {
if(stype[j] == 2) {
if(location[j] * 2 - pos - location[0] == d)
ok = true;
}
}
if(ok) {
fix(i, pos, 1);
if(pos < location[L]) L = i;
continue;
}
}
{ // [])
int pos = location[L] + a;
fix(i, pos, 2);
R = i;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
104 ms |
564 KB |
Output is correct |
2 |
Correct |
106 ms |
512 KB |
Output is correct |
3 |
Correct |
122 ms |
616 KB |
Output is correct |
4 |
Correct |
133 ms |
604 KB |
Output is correct |
5 |
Correct |
112 ms |
608 KB |
Output is correct |
6 |
Correct |
120 ms |
604 KB |
Output is correct |
7 |
Correct |
111 ms |
608 KB |
Output is correct |
8 |
Correct |
106 ms |
608 KB |
Output is correct |
9 |
Correct |
106 ms |
608 KB |
Output is correct |
10 |
Correct |
115 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
106 ms |
560 KB |
Output is correct |
2 |
Correct |
106 ms |
608 KB |
Output is correct |
3 |
Correct |
109 ms |
608 KB |
Output is correct |
4 |
Correct |
109 ms |
588 KB |
Output is correct |
5 |
Correct |
126 ms |
604 KB |
Output is correct |
6 |
Correct |
113 ms |
588 KB |
Output is correct |
7 |
Correct |
110 ms |
604 KB |
Output is correct |
8 |
Correct |
113 ms |
608 KB |
Output is correct |
9 |
Correct |
107 ms |
588 KB |
Output is correct |
10 |
Correct |
122 ms |
516 KB |
Output is correct |
11 |
Correct |
109 ms |
608 KB |
Output is correct |
12 |
Correct |
123 ms |
496 KB |
Output is correct |
13 |
Correct |
110 ms |
612 KB |
Output is correct |
14 |
Correct |
105 ms |
604 KB |
Output is correct |
15 |
Correct |
107 ms |
508 KB |
Output is correct |
16 |
Correct |
105 ms |
612 KB |
Output is correct |
17 |
Correct |
110 ms |
588 KB |
Output is correct |
18 |
Correct |
122 ms |
640 KB |
Output is correct |
19 |
Correct |
123 ms |
500 KB |
Output is correct |
20 |
Correct |
110 ms |
492 KB |
Output is correct |