이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "rail.h"
using namespace std;
int d[5001][5001];
void findLocation(int n, int f, int location[], int stype[])
{
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
d[i][j] = d[j][i] = getDistance(i,j);
}
}
location[0] = f;
stype[0] = 1;
vector<int>mn(n,0);
for(int i=0;i<n;i++){
int c = 1e9;
for(int j=0;j<n;j++){
if(i==j)continue;
if(c > d[i][j]){
c = d[i][j];
mn[i] = j;
}
}
}
int x = mn[0];
stype[x] = 2;
location[x] = f + d[x][0];
vector<int>l,r;
for(int i=0;i<n;i++){
if(i==0 || i==x)continue;
if(d[0][i] == d[0][x] + d[x][i])l.push_back(i);
else r.push_back(i);
}
int c0 = 0,c1 = x;
//for(int x:r)cout<<x<<'\n';
while(!l.empty()){ //solbve for each block of (down,up)
vector<int>tmp;
for(int a:l){ //completing this block
if(mn[a] == c0){
stype[a] = 2;
location[a] = location[c0] + d[c0][a];
}else if(mn[a] == c1){
stype[a] = 1;
location[a] = location[c1] - d[c1][a];
}else{
tmp.push_back(a);
}
}
if(!tmp.empty()){
int c = 1e9;
int can = 0;
for(int a:tmp){
if(c > d[a][c1]){
c = d[a][c1];
can = a;
}
}
stype[can] = 1;
location[can] = location[c1] - d[can][c1];
c0 = can;
c1 = mn[can];
stype[c1] = 2;
location[c1] = location[c0] + d[c0][c1];
vector<int>tmp2;
for(int a:tmp){
if(a!=c0 && a!=c1)tmp2.push_back(a);
}
swap(tmp,tmp2);
}
swap(l,tmp);
}
c0 = 0;
c1 = x;
while(!r.empty()){
vector<int>tmp;
for(int a:r){ //completing this block
if(mn[a] == c0){
stype[a] = 2;
location[a] = location[c0] + d[c0][a];
}else if(mn[a] == c1){
stype[a] = 1;
location[a] = location[c1] - d[c1][a];
}else{
tmp.push_back(a);
}
}
if(!tmp.empty()){
int c = 1e9;
int can = 0;
for(int a:tmp){
if(c > d[a][c0]){
c = d[a][c0];
can = a;
}
}
stype[can] = 2;
location[can] = location[c0] + d[can][c0];
c0 = mn[can];
c1 = can;
stype[c0] = 1;
location[c0] = location[c1] - d[c0][c1];
vector<int>tmp2;
for(int a:tmp){
if(a!=c0 && a!=c1)tmp2.push_back(a);
}
swap(tmp,tmp2);
}
swap(r,tmp);
}
//for(int i=0;i<n;i++)cout<<stype[i]<<" "<<location[i]<<'\n';
}
# | 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... |