# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1037053 | HappyCapybara | Sky Walking (IOI19_walk) | C++17 | 4056 ms | 702616 KiB |
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<pair<int,int>>> sws(n, {{0, 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({y[i], i});
}
}
y.push_back(0);
for (int i=0; i<n; i++) sort(sws[i].begin(), sws[i].end());
map<ll,vector<int>> pn;
for (int i=0; i<n; i++){
if (sws[i].size() == 0) continue;
for (int j=0; j<sws[i].size(); j++){
if (j < sws[i].size()-1) pn[i*100001+sws[i][j].second].push_back(sws[i][j+1].second);
if (j > 0) pn[i*100001+sws[i][j].second].push_back(sws[i][j-1].second);
}
}
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 : pn[bld*100001+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;
}
Compilation message (stderr)
# | 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... |