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<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);
continue;
}
}
{
int pos = location[R] - b;
bool ok = false;
REP(j, N) {
if(stype[j] == 2) {
if(location[j] * 2 - pos - location[L] == a)
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;
}
}
}
Compilation message (stderr)
rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:27:17: warning: unused variable 'd' [-Wunused-variable]
for(auto &[d, i] : stations) {
^
# | 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... |