#include <bits/stdc++.h>
#include "rail.h"
// mrrrow meeeow nyaa :3c
// play vivid/stasis! it's a really awesome free game on steam
#define fo(i, a, b) for (auto i = (a); i < (b); i++)
#define of(i, a, b) for (auto i = (b); i-- > (a);)
#define pb push_back
#define pob pop_back
#define p push
#define po pop
#define f first
#define s second
#define ub upper_bound
#define lb lower_bound
#define be(a) a.begin(), a.end()
using namespace std;
int ____init = []
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
return 0;
}();
map<pair<int, int>, int> cache;
int dist(int i, int j)
{
if (i == j)
return 0;
if (i > j)
swap(i, j);
if (cache.count({i, j}))
return cache[{i, j}];
return cache[{i, j}] = getDistance(i, j);
}
void findLocation(int n, int first, int location[], int stype[])
{
vector<int> b;
location[0] = first;
stype[0] = 1;
fo(i, 1, n)
{
location[i] = first + dist(0, i), stype[i] = 2;
b.pb(i);
}
sort(be(b), [&](int &i, int &j)
{ return location[i] < location[j]; });
vector<int> c;
vector<int> d;
for (int i : b)
{
of(j, 0, c.size())
{
if (location[c[j]] - (j > 0 ? location[c[j - 1]] : -10000000) > location[i] - location[c[j]] && dist(0, i) == dist(0, c[j]) + dist(c[j], i))
{
location[i] -= 2 * dist(c[j], i);
stype[i] = 1;
if (location[i] < first)
d.pb(i);
goto cont;
}
}
c.pb(i);
cont:;
}
sort(be(d), [&](int &i, int &j)
{ return location[i] > location[j]; });
vector<int> e = {0};
for (int i : d)
{
of(j, 1, e.size())
{
if (location[e[j - 1]] - location[e[j]] > location[e[j]] - location[i] && dist(0, i) == dist(0, e[j]) + dist(e[j], i))
{
location[i] += 2 * dist(e[j], i);
stype[i] = 2;
goto cont2;
}
}
e.pb(i);
cont2:;
}
}
# | 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... |