#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
#define _all(T) T.begin(),T.end()
#define ll long long
#define pii pair<int,int>
#define fs first
#define sc second
#define pll pair<ll,ll>
const int mxn = 2e6+10;
const ll inf = 1e18;
vector<pii> paths[mxn];
ll dist[mxn];
int N;
vector<pii> pts;
set<int> st;
vector<pii> op;
namespace DIJKSTRA{
priority_queue<pll,vector<pll>,greater<pll>> pq;
bitset<mxn> vis;
void GO(){
vis.reset();
for(int i = 0;i<pts.size();i++)pq.push(pll(dist[i],i));
while(!pq.empty()){
auto [d,now] = pq.top();
pq.pop();
if(vis[now])continue;
vis[now] = true;
for(auto [nxt,w]:paths[now]){
if(vis[nxt]||d+w>=dist[nxt])continue;
dist[nxt] = d+w;
pq.push(pll(d+w,nxt));
}
}
return;
}
}
long long min_distance(std::vector<int32_t> x, std::vector<int32_t> H, std::vector<int32_t> l, std::vector<int32_t> r, std::vector<int32_t> y, int32_t s, int32_t ed) {
N = x.size();
for(int i = 0;i<N;i++){
op.push_back(pii(H[i],i));
}
for(int i = 0;i<l.size();i++){
op.push_back(pii(y[i],-i-1));
}
sort(op.rbegin(),op.rend());
for(auto [h,id]:op){
if(id>=0){
pts.push_back(pii(id,h));
st.insert(id);
}
else{
id = -id;
id--;
auto lit = st.lower_bound(l[id]);
auto rit = st.upper_bound(r[id]);
for(auto it = lit;it != rit;it++){
pts.push_back(pii(*it,h));
}
id = -id;
}
}
for(int i = 0;i<N;i++)pts.push_back(pii(i,0));
sort(pts.begin(),pts.end());
pts.resize(unique(pts.begin(),pts.end())-pts.begin());
st.clear();
for(auto [h,id]:op){
if(id>=0){
st.insert(id);
}
else{
id = -id;
id--;
auto lit = st.find(l[id]);
auto rit = st.upper_bound(r[id]);
int pre = lower_bound(_all(pts),pii(*lit,h))-pts.begin();
for(auto it = lit;it != rit;it++){
int now = lower_bound(_all(pts),pii(*it,h))-pts.begin();
if(it != lit){
paths[now].push_back(pii(pre,x[*it]-x[*prev(it)]));
paths[pre].push_back(pii(now,x[*it]-x[*prev(it)]));
}
pre = now;
}
}
}
for(int i = 1;i<pts.size();i++){
if(pts[i].fs == pts[i-1].fs){
paths[i].push_back(pii(i-1,pts[i].sc-pts[i-1].sc));
paths[i-1].push_back(pii(i,pts[i].sc-pts[i-1].sc));
}
}
fill(dist,dist+pts.size(),inf);
s = lower_bound(pts.begin(),pts.end(),pii(s,0))-pts.begin();
ed = lower_bound(pts.begin(),pts.end(),pii(ed,0))-pts.begin();
dist[s] = 0;
DIJKSTRA::GO();
ll ans = dist[ed];
return ans>=inf?-1:ans;
}
Compilation message
walk.cpp: In function 'void DIJKSTRA::GO()':
walk.cpp:27:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for(int i = 0;i<pts.size();i++)pq.push(pll(dist[i],i));
| ~^~~~~~~~~~~
walk.cpp: In function 'long long int min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int32_t, int32_t)':
walk.cpp:48:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int i = 0;i<l.size();i++){
| ~^~~~~~~~~
walk.cpp:96:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
96 | for(int i = 1;i<pts.size();i++){
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
50776 KB |
Output is correct |
2 |
Correct |
8 ms |
50776 KB |
Output is correct |
3 |
Correct |
8 ms |
50976 KB |
Output is correct |
4 |
Correct |
8 ms |
50936 KB |
Output is correct |
5 |
Correct |
8 ms |
51032 KB |
Output is correct |
6 |
Correct |
8 ms |
50904 KB |
Output is correct |
7 |
Correct |
8 ms |
50916 KB |
Output is correct |
8 |
Correct |
8 ms |
51036 KB |
Output is correct |
9 |
Correct |
9 ms |
50780 KB |
Output is correct |
10 |
Correct |
12 ms |
51036 KB |
Output is correct |
11 |
Correct |
8 ms |
50776 KB |
Output is correct |
12 |
Correct |
9 ms |
50780 KB |
Output is correct |
13 |
Correct |
8 ms |
50780 KB |
Output is correct |
14 |
Correct |
11 ms |
50948 KB |
Output is correct |
15 |
Correct |
8 ms |
50780 KB |
Output is correct |
16 |
Correct |
8 ms |
50908 KB |
Output is correct |
17 |
Correct |
9 ms |
51036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
50776 KB |
Output is correct |
2 |
Correct |
9 ms |
50912 KB |
Output is correct |
3 |
Correct |
711 ms |
121372 KB |
Output is correct |
4 |
Correct |
889 ms |
135496 KB |
Output is correct |
5 |
Correct |
547 ms |
128188 KB |
Output is correct |
6 |
Correct |
492 ms |
124096 KB |
Output is correct |
7 |
Correct |
556 ms |
128640 KB |
Output is correct |
8 |
Correct |
904 ms |
132040 KB |
Output is correct |
9 |
Correct |
651 ms |
125500 KB |
Output is correct |
10 |
Correct |
1117 ms |
171476 KB |
Output is correct |
11 |
Correct |
447 ms |
94960 KB |
Output is correct |
12 |
Correct |
410 ms |
92744 KB |
Output is correct |
13 |
Correct |
946 ms |
164748 KB |
Output is correct |
14 |
Correct |
246 ms |
92420 KB |
Output is correct |
15 |
Correct |
306 ms |
87844 KB |
Output is correct |
16 |
Correct |
273 ms |
88900 KB |
Output is correct |
17 |
Correct |
277 ms |
88852 KB |
Output is correct |
18 |
Correct |
209 ms |
96148 KB |
Output is correct |
19 |
Correct |
16 ms |
52696 KB |
Output is correct |
20 |
Correct |
101 ms |
68612 KB |
Output is correct |
21 |
Correct |
272 ms |
89100 KB |
Output is correct |
22 |
Correct |
302 ms |
87520 KB |
Output is correct |
23 |
Correct |
257 ms |
91964 KB |
Output is correct |
24 |
Correct |
290 ms |
90120 KB |
Output is correct |
25 |
Correct |
288 ms |
87812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
60476 KB |
Output is correct |
2 |
Runtime error |
594 ms |
193448 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
60476 KB |
Output is correct |
2 |
Runtime error |
594 ms |
193448 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
50776 KB |
Output is correct |
2 |
Correct |
8 ms |
50776 KB |
Output is correct |
3 |
Correct |
8 ms |
50976 KB |
Output is correct |
4 |
Correct |
8 ms |
50936 KB |
Output is correct |
5 |
Correct |
8 ms |
51032 KB |
Output is correct |
6 |
Correct |
8 ms |
50904 KB |
Output is correct |
7 |
Correct |
8 ms |
50916 KB |
Output is correct |
8 |
Correct |
8 ms |
51036 KB |
Output is correct |
9 |
Correct |
9 ms |
50780 KB |
Output is correct |
10 |
Correct |
12 ms |
51036 KB |
Output is correct |
11 |
Correct |
8 ms |
50776 KB |
Output is correct |
12 |
Correct |
9 ms |
50780 KB |
Output is correct |
13 |
Correct |
8 ms |
50780 KB |
Output is correct |
14 |
Correct |
11 ms |
50948 KB |
Output is correct |
15 |
Correct |
8 ms |
50780 KB |
Output is correct |
16 |
Correct |
8 ms |
50908 KB |
Output is correct |
17 |
Correct |
9 ms |
51036 KB |
Output is correct |
18 |
Correct |
9 ms |
50776 KB |
Output is correct |
19 |
Correct |
9 ms |
50912 KB |
Output is correct |
20 |
Correct |
711 ms |
121372 KB |
Output is correct |
21 |
Correct |
889 ms |
135496 KB |
Output is correct |
22 |
Correct |
547 ms |
128188 KB |
Output is correct |
23 |
Correct |
492 ms |
124096 KB |
Output is correct |
24 |
Correct |
556 ms |
128640 KB |
Output is correct |
25 |
Correct |
904 ms |
132040 KB |
Output is correct |
26 |
Correct |
651 ms |
125500 KB |
Output is correct |
27 |
Correct |
1117 ms |
171476 KB |
Output is correct |
28 |
Correct |
447 ms |
94960 KB |
Output is correct |
29 |
Correct |
410 ms |
92744 KB |
Output is correct |
30 |
Correct |
946 ms |
164748 KB |
Output is correct |
31 |
Correct |
246 ms |
92420 KB |
Output is correct |
32 |
Correct |
306 ms |
87844 KB |
Output is correct |
33 |
Correct |
273 ms |
88900 KB |
Output is correct |
34 |
Correct |
277 ms |
88852 KB |
Output is correct |
35 |
Correct |
209 ms |
96148 KB |
Output is correct |
36 |
Correct |
16 ms |
52696 KB |
Output is correct |
37 |
Correct |
101 ms |
68612 KB |
Output is correct |
38 |
Correct |
272 ms |
89100 KB |
Output is correct |
39 |
Correct |
302 ms |
87520 KB |
Output is correct |
40 |
Correct |
257 ms |
91964 KB |
Output is correct |
41 |
Correct |
290 ms |
90120 KB |
Output is correct |
42 |
Correct |
288 ms |
87812 KB |
Output is correct |
43 |
Correct |
97 ms |
60476 KB |
Output is correct |
44 |
Runtime error |
594 ms |
193448 KB |
Execution killed with signal 11 |
45 |
Halted |
0 ms |
0 KB |
- |