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 "rail.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<ii> vii;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define RE(a,b) REP(a,0,b)
#define RE1(a,b) REP(a,1,b+1)
#define FOR(a,b) for(auto& a : b)
#define pb push_back
#define fi first
#define se second
#define all(a) a.begin(),a.end()
const int MX = 6000;
int mem[MX][MX];
void findLocation(int n, int first, int location[], int stype[]) {
RE(i,n) RE(j,n) mem[i][j] = -1;
auto getD = [&](int u, int v) {
if(u == v) return 0;
if(mem[u][v] != -1)
return mem[u][v];
return mem[u][v] = mem[v][u] = getDistance(u,v);
};
RE(i,n) location[i] = -1;
int closest = 1e9;
REP(i,1,n)
closest = min(closest, getD(0,i));
int u = -1;
REP(i,1,n)
if(getD(0,i) == closest)
u = i;
stype [0] = 1;
location[0] = first;
stype [u] = 2;
location[u] = first + getD(0,u);
vii pql, pqr;
REP(i,1,n) {
if(i == u) continue;
int d0 = getD(i,0);
int du = getD(i,u);
if(getD(0,u) + du == d0 && du < getD(0,u)) {
stype [i] = 1;
location[i] = location[u] - du;
} else if(getD(0,u) + du == d0) {
pql.pb({du,i});
} else {
pqr.pb({d0,i});
}
}
sort(all(pql));
sort(all(pqr));
int x = u;
FOR(p,pqr) {
int i = p.se;
int z = getD(0,x) + getD(x,i) - getD(0,i);
z /= 2;
int type = 1;
RE(j,n)
if(location[j] == location[x] - z)
type = stype[j];
if(type == 1) {
location[i] = location[0] + getD(0,i);
stype [i] = 2;
x = i;
} else {
location[i] = location[x] - getD(x,i);
stype [i] = 1;
}
}
x = 0;
FOR(p,pql) {
int i = p.se;
int z = getD(u,x) + getD(x,i) - getD(u,i);
z /= 2;
int type = 2;
RE(j,n)
if(location[j] == location[x] + z)
type = stype[j];
if(type == 2) {
location[i] = location[u] - getD(u,i);
stype [i] = 1;
x = i;
} else {
location[i] = location[x] + getD(x,i);
stype [i] = 2;
}
}
}
# | 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... |