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;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
typedef pair<int,int> ii;
#define maxn 1005
int dist[maxn];
vector<int> stuff[maxn];
vector<ii> v,l,r;
void findLocation(int N,int first,int location[],int stype[]){
location[0]=first;stype[0]=1;
for(int i=1;i<N;++i){
location[i]=-1;
dist[i]=getDistance(0,i);
v.pb({dist[i],i});
}
sort(all(v),greater<ii>());
//printf("v: ");
//for(auto[a,b]:v)printf("(%d %d) ",a,b);
//printf("\n");
int second=v.back().se;
location[second]=first+dist[second];
stype[second]=2;
v.pop_back();
while(!v.empty()){
auto[d,x]=v.back();
v.pop_back();
if(dist[x]==dist[second]+getDistance(second,x))l.pb({d,x});
else r.pb({d,x});
}
//printf("l: ");
//for(auto[a,b]:l)printf("(%d %d) ",a,b);
//printf("\n");
//printf("r: ");
//for(auto[a,b]:r)printf("(%d %d) ",a,b);
//printf("\n");
int pv=-1;
for(int i=0;i<r.size();++i){
auto[_,x]=r[i];
if(pv==-1){
location[x]=first+dist[x];
stype[x]=2;
pv=x;
continue;
}
int tmp=getDistance(pv,x);
if(dist[x]==dist[pv]+tmp){
location[x]=location[pv]-tmp;
stype[x]=1;
}
else{
int extra=(dist[pv]+tmp-dist[x])/2;
for(int i=0;i<N;++i){
if(location[i]!=-1&&location[i]==location[pv]-extra){
if(stype[i]==1){
location[x]=first+dist[x];
stype[x]=2;
pv=x;
}
else{
location[x]=location[pv]-tmp;
stype[x]=1;
}
break;
}
}
}
}
pv=-1;
for(int i=0;i<l.size();++i){
auto[_,x]=l[i];
if(pv==-1){
location[x]=location[second]-dist[x]+dist[second];
stype[x]=1;
pv=x;
continue;
}
int tmp=getDistance(pv,x);
if(dist[x]==dist[pv]+tmp){
location[x]=location[pv]+tmp;
stype[x]=2;
}
else{
int extra=(dist[pv]+tmp-dist[x])/2;
for(int i=0;i<N;++i){
if(location[i]!=-1&&location[i]==location[pv]+extra){
if(stype[i]==1){
location[x]=location[pv]+tmp;
stype[x]=2;
pv=x;
}
else{
location[x]=location[second]-dist[x]+dist[second];
stype[x]=1;
pv=x;
}
break;
}
}
}
}
//printf("ans:\n");
//for(int i=0;i<N;++i)printf("%d ",location[i]);printf("\n");
//for(int i=0;i<N;++i)printf("%d ",stype[i]);printf("\n");
}
Compilation message (stderr)
rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:48:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int i=0;i<r.size();++i){
| ~^~~~~~~~~
rail.cpp:81:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | for(int i=0;i<l.size();++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... |