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;
const int maxn = 5e3 + 10;
int d0[maxn], a[maxn], rough[maxn];
int pos;
int ban[maxn];
int rec[maxn][maxn];
int ask(int x, int y) {
if(x>y) swap(x,y);
if(x==y) return 0;
if(!rec[x][y]) rec[x][y] = getDistance(x,y);
// printf("\task %d %d = %d\n",x,y,rec[x][y]);
return rec[x][y];
}
bool cmpd(int x, int y) {
return d0[x]<d0[y];
}
void findLocation(int N, int first, int location[], int stype[]) {
//find right
for(int i=0;i<N;i++) d0[i] = ask(0,i);
for(int i=0;i<N;i++) a[i] = i;
sort(&a[0],&a[N],cmpd);
pos = a[1];
for(int i=2;i<N;i++) {
int x = a[i];
if(ask(0,x)==ask(a[1],x)+ask(0,a[1])) continue;
if(ask(0,x)!=ask(pos,x)+ask(0,pos)) pos = x;
}
// printf("pos = %d\n",pos);
//solve
memset(ban,0,sizeof(ban));
ban[pos] = 1;
location[pos] = first + ask(0,pos);
stype[pos] = 2;
while(1) {
int x = -1;
//nearest C
for(int i=0;i<N;i++) {
if(!ban[i] && (x==-1 || ask(pos,i)<ask(pos,x))) {
x = i;
}
}
if(x==-1) break;
ban[x] = 1;
location[x] = location[pos] - ask(pos,x);
stype[x] = 1;
// printf("%d (%d): ",x,location[x]);
//sweep right
for(int i=0;i<N;i++) {
if(!ban[i] && ask(pos,i)-ask(pos,x)==ask(x,i)) {
ban[i] = 1;
location[i] = location[x] + ask(x,i);
stype[i] = 2;
// printf("%d (%d) ",i,location[i]);
}
}
// printf("\n");
}
// for(int i=0;i<N;i++) printf("%d %d\n",stype[i],location[i]);
}
# | 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... |