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 "walk.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
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<vector<int>> sws(n, vector<int>(1, m));
for (int i=0; i<m; i++){
for (int j=l[i]; j<=r[i]; j++){
if (y[i] <= h[j]) sws[j].push_back(i);
}
}
y.push_back(0);
priority_queue<vector<ll>> pq;
unordered_set<ll> seen;
pq.push({0, s, m});
while (!pq.empty()){
ll d = -pq.top()[0];
int bld = pq.top()[1], sw = pq.top()[2];
pq.pop();
//cout << d << " " << bld << " " << sw << "\n";
if (bld == g && sw == m) return d;
if (seen.find(bld*100001+sw) != seen.end()) continue;
seen.insert(bld*100001+sw);
for (int next : sws[bld]){
if (next != sw) pq.push({-(d+abs(y[next]-y[sw])), bld, next});
}
if (sw == m) continue;
for (int next=l[sw]; next<=r[sw]; next++){
if (next != bld && h[next] >= y[sw]) pq.push({-(d+abs(x[next]-x[bld])), next, sw});
}
}
return -1;
}
# | 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... |