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<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
ll min_distance(vector<int>x,vector<int>h,vector<int>l,vector<int>r,vector<int>y,int s,int g){
int n=x.size(),m=l.size();
vector<int>Y=y;
sort(all(Y));
vector<int>d;
d.pb(0);
for(int i=0;i<Y.size();i++){
if(i==0||Y[i]!=Y[i-1]){
d.pb(Y[i]);
}
}
vector<int>y_ind(y.size());
for(int i=0;i<m;i++){
y_ind[i]=lower_bound(all(d),y[i])-d.begin();
}
vector<pair<int,int>>adj[n][m+1];
ll dist[n][m+1];
if(n<=50&&m<=50){
for(int i=0;i<n;i++){
for(int j=0;j<=m;j++){
dist[i][j]=1e18;
}
}
for(int j=0;j<m;j++){
int last=-1;
for(int i=l[j];i<=r[j];i++){
if(h[i]>=y[j]){
if(last>-1){
adj[last][y_ind[j]].pb({i,y_ind[j]});
adj[i][y_ind[j]].pb({last,y_ind[j]});
}
last=i;
}
}
}
for(int i=0;i<n;i++){
for(int j=1;j<d.size();j++){
if(d[j]<=h[i]){
adj[i][j-1].pb({i,j});
adj[i][j].pb({i,j-1});
}
}
}
}
set<tuple<ll,int,int>>st;
st.insert({0,s,0});
dist[s][0]=0;
while(!st.empty()){
auto [cur,ni,nj]=*st.begin();
st.erase(st.begin());
if(dist[ni][nj]!=cur) continue;
for(auto [nx,ny]:adj[ni][nj]){
ll new_cur=cur+abs(x[ni]-x[nx])+abs(d[nj]-d[ny]);
if(new_cur<dist[nx][ny]){
dist[nx][ny]=new_cur;
st.insert({new_cur,nx,ny});
}
}
}
if(dist[g][0]==1e18) dist[g][0]=-1;
return dist[g][0];
}
Compilation message (stderr)
walk.cpp: In function 'long long int min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:18:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for(int i=0;i<Y.size();i++){
| ~^~~~~~~~~
walk.cpp:48:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int j=1;j<d.size();j++){
| ~^~~~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |