#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 |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
175 ms |
736 KB |
Output is correct |
2 |
Correct |
180 ms |
632 KB |
Output is correct |
3 |
Correct |
187 ms |
632 KB |
Output is correct |
4 |
Correct |
183 ms |
632 KB |
Output is correct |
5 |
Correct |
181 ms |
632 KB |
Output is correct |
6 |
Correct |
187 ms |
760 KB |
Output is correct |
7 |
Correct |
185 ms |
632 KB |
Output is correct |
8 |
Correct |
182 ms |
632 KB |
Output is correct |
9 |
Correct |
184 ms |
632 KB |
Output is correct |
10 |
Correct |
187 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
182 ms |
504 KB |
Output is correct |
2 |
Correct |
189 ms |
632 KB |
Output is correct |
3 |
Correct |
183 ms |
636 KB |
Output is correct |
4 |
Correct |
181 ms |
764 KB |
Output is correct |
5 |
Correct |
185 ms |
632 KB |
Output is correct |
6 |
Correct |
186 ms |
632 KB |
Output is correct |
7 |
Correct |
189 ms |
632 KB |
Output is correct |
8 |
Correct |
184 ms |
636 KB |
Output is correct |
9 |
Correct |
184 ms |
632 KB |
Output is correct |
10 |
Correct |
185 ms |
760 KB |
Output is correct |
11 |
Correct |
181 ms |
632 KB |
Output is correct |
12 |
Correct |
186 ms |
632 KB |
Output is correct |
13 |
Correct |
178 ms |
632 KB |
Output is correct |
14 |
Correct |
175 ms |
632 KB |
Output is correct |
15 |
Correct |
182 ms |
632 KB |
Output is correct |
16 |
Correct |
182 ms |
632 KB |
Output is correct |
17 |
Correct |
191 ms |
632 KB |
Output is correct |
18 |
Correct |
180 ms |
632 KB |
Output is correct |
19 |
Correct |
186 ms |
632 KB |
Output is correct |
20 |
Correct |
194 ms |
760 KB |
Output is correct |