#include "rail.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
const int maxn=5010;
vector<vi> mem(maxn,vi(maxn,-1));
int get(int i, int j) {
if (mem[i][j]!=-1) {
return mem[i][j];
}
if (mem[j][i]!=-1) {
return mem[j][i];
}
return mem[i][j]=getDistance(i,j);
}
void find(int k, int side, vi& inds, int loc[], int tpe[]) {
if (inds.size()==0) {
return;
}
int mn=inds[0];
for (auto i:inds) {
if (get(k,i)<get(k,mn)) {
mn=i;
}
}
loc[mn]=loc[k]+side*get(k,mn);
tpe[mn]=(side==1?2:1);
vi newinds;
int clo=k;
for (auto i:inds) {
if (i==mn) {
continue;
}
if (get(k,i)==get(k,mn)+get(mn,i) && get(mn,i)<get(k,mn)) {
if (get(mn,i)<get(clo,mn)) {
clo=i;
}
loc[i]=loc[mn]-side*get(mn,i);
tpe[i]=(side==1?1:2);
}
else {
newinds.pb(i);
}
}
vi indsl,indsr;
for (auto i:newinds) {
if (get(mn,i)<get(clo,i)) {
indsl.pb(i);
}
else {
indsr.pb(i);
}
}
find(clo,side,indsr,loc,tpe);
find(mn,-side,indsl,loc,tpe);
}
void findLocation(int n, int f, int loc[], int tpe[]) {// sub 3
for (int i=0; i<n; i++) {
mem[i][i]=0;
}
loc[0]=f;
tpe[0]=1;
vi inds(n-1);
iota(all(inds),1);
find(0,1,inds,loc,tpe);
}
# | 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... |