#include "rail.h"
#include<bits/stdc++.h>
using namespace std;
int mp[5005][5005];
const int INF = 1e9;
int ramase;
int getd(int x, int y)
{
if(x==y)
return 0;
if(x<0 || y<0)
return INF;
if(x>y)
swap(x,y);
if(mp[x][y]==0)
{
if(ramase==0)
while(1);
ramase--;
mp[x][y] = getDistance(x,y);
}
return mp[x][y];
}
void findLocation(int N, int first, int location[], int stype[])
{
ramase = 3*(N-1);
location[0] = first;
stype[0] = 1;
vector<pair<int,int>> d0;
for(int i=1;i<N;i++)
d0.push_back({getd(0,i),i});
sort(d0.begin(),d0.end());
int p=d0[0].second;
location[p] = location[0] + getd(0,p);
stype[p] = 2;
for(int pas=1;pas<d0.size();pas++)
{
int i = d0[pas].second;
if(stype[i]!=0)
continue;
if(getd(0,i) == getd(0,p) + getd(p,i))
{
stype[i] = 1;
location[i] = location[p] - getd(p,i);
for(auto [_,j]:d0)
{
if(stype[j]!=0)
continue;
if(getd(0,j) == getd(0,p) + getd(p,j) && getd(0,j) > getd(0,p) + getd(p,i) && getd(0,j) < getd(0,p) + getd(p,i) + getd(0,i))
{
if(getd(0,j) == getd(0,p) + getd(p,i) + getd(i,j))
{
stype[j] = 2;
location[j] = location[i] + getd(i,j);
}
}
/*
.(..(.)....())(((((()()(()..)..
i 0 p
*/
}
}
else
{
stype[i] = 2;
location[i] = location[0] + getd(0,i);
for(int j=0;j<N;j++)
{
if(stype[j]!=0)
continue;
if(getd(i,j) < getd(0,i) && getd(0,j) == getd(0,i) + getd(i,j))
{
stype[j] = 1;
location[j] = location[i] - getd(i,j);
}
}
}
}
//for(int i=0;i<N;i++) cerr<<stype[i]<<" "<<location[i]<<" final\n";
}
/*
........(((((()........
0 p
.(..(.).())(((((()()(()..)..
i 0 p
2
6
1 10
1 7
1 3
2 12
2 15
2 20
*/
# | 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... |