#include "walk.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;
priority_queue <pair <int, int>, vector <pair <int, int>>, greater <pair <int, int>>> q;
vector <int> a[100001],b[100001];
vector <pair <int, int>> ke[12000001],ve,nodes;
int n,m,d[12000001];
set <int> S;
void add(int i, int j){
a[i].push_back(j);
nodes.push_back({i,j});
}
int f(int i, int j){
return lower_bound(nodes.begin(),nodes.end(),make_pair(i,j))-nodes.begin();
}
long long min_distance(vector<int32_t> x, vector<int32_t> h, vector<int32_t> l, vector<int32_t> r, vector<int32_t> y, int32_t s, int32_t g){
n=x.size(),m=l.size();
for (int i=0;i<n;i++)
ve.push_back({-h[i],-i});
for (int i=0;i<m;i++)
ve.push_back({-y[i],i+1});
sort(ve.begin(),ve.end());
for (auto [i,j]:ve){
i=-i,j=-j;
if (j>=0){
S.insert(j);
continue;
}
j=-j-1;
for (auto it=S.lower_bound(l[j]);it!=S.end()&&*it<=r[j];it++){
add(*it,j);
b[j].push_back(*it);
}
}
add(s,-1);
add(g,-1);
sort(nodes.begin(),nodes.end());
nodes.resize(unique(nodes.begin(),nodes.end())-nodes.begin());
for (int i=0;i<n;i++)
for (int j=0;j<(int)a[i].size()-1;j++){
int u=f(i,a[i][j]),v=f(i,a[i][j+1]),w=abs((a[i][j]>=0?y[a[i][j]]:0)-(a[i][j+1]>=0?y[a[i][j+1]]:0));
ke[u].push_back({v,w});
ke[v].push_back({u,w});
}
for (int i=0;i<m;i++)
for (int j=0;j<(int)b[i].size()-1;j++){
int u=f(b[i][j],i),v=f(b[i][j+1],i),w=x[b[i][j+1]]-x[b[i][j]];
ke[u].push_back({v,w});
ke[v].push_back({u,w});
}
fill(d,d+nodes.size(),1e18);
d[f(s,-1)]=0;
q.push({0,f(s,-1)});
while (!q.empty()){
auto [du,u]=q.top();
q.pop();
if (du!=d[u])
continue;
for (auto [v,w]:ke[u])
if (d[v]>d[u]+w){
d[v]=d[u]+w;
q.push({d[v],v});
}
}
return d[f(g,-1)];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
288344 KB |
Output is correct |
2 |
Correct |
62 ms |
288252 KB |
Output is correct |
3 |
Correct |
64 ms |
288144 KB |
Output is correct |
4 |
Incorrect |
62 ms |
288152 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
288340 KB |
Output is correct |
2 |
Correct |
61 ms |
288336 KB |
Output is correct |
3 |
Correct |
1050 ms |
394460 KB |
Output is correct |
4 |
Correct |
1008 ms |
401196 KB |
Output is correct |
5 |
Correct |
761 ms |
385420 KB |
Output is correct |
6 |
Correct |
631 ms |
372864 KB |
Output is correct |
7 |
Incorrect |
762 ms |
385432 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
175 ms |
307896 KB |
Output is correct |
2 |
Execution timed out |
4083 ms |
893140 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
175 ms |
307896 KB |
Output is correct |
2 |
Execution timed out |
4083 ms |
893140 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
288344 KB |
Output is correct |
2 |
Correct |
62 ms |
288252 KB |
Output is correct |
3 |
Correct |
64 ms |
288144 KB |
Output is correct |
4 |
Incorrect |
62 ms |
288152 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |