#include "walk.h"
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+5;
const int grafs=5e6+5;
ll N,M;
struct skywalk{
ll l,r,y;
} put[maxn];
struct zgrada{
ll x,y,id;
} niz[maxn];
bool cmpsw(skywalk a,skywalk b){
return a.y<b.y;
}
bool poy(zgrada a,zgrada b){
return a.y<b.y;
}
int gsz=0;
int novi(){
return ++gsz;
}
set<int> S;
vector<pair<int,int>> koji[maxn];
vector<pair<ll,ll>> graf[grafs];
bool prosli[grafs];
ll dist[grafs];
priority_queue<pair<ll,ll>> PQ;
void grana(int a,int b,ll w){
graf[a].push_back({b,w});
graf[b].push_back({a,w});
}
void Dijkstra(ll gde,ll c){
PQ.push({-c,gde});
while(PQ.size()){
ll tren=PQ.top().second;
ll d=-PQ.top().first;
PQ.pop();
if(prosli[tren])
continue;
prosli[tren]=true;
dist[tren]=d;
for(auto x:graf[tren])
PQ.push({-d-x.second,x.first});
}
}
ll min_distance(std::vector<int> x, std::vector<int> h, std::vector<int> l, std::vector<int> r, std::vector<int> y, int s, int g) {
N=x.size();
M=l.size();
for(ll i=0;i<N;i++){
niz[i].x=x[i];
niz[i].y=h[i];
niz[i].id=i;
}
for(ll i=0;i<M;i++){
put[i].l=l[i];
put[i].r=r[i];
put[i].y=y[i];
}
sort(niz,niz+N,poy);
sort(put,put+M,cmpsw);
ll pok=N-1;
for(ll i=M-1;i>=0;i--){
if(pok>=0){
while(niz[pok].y>=put[i].y){
S.insert(niz[pok].id);
pok--;
if(pok<0)
break;
}
}
if(S.size()==0)
continue;
vector<ll> V;
auto it=S.upper_bound(put[i].l-1);
for(it;it!=S.end();it++){
if((*it)>put[i].r)
break;
V.push_back(*it);
}
if(V.size()==0)
continue;
int pn=novi();
koji[V[0]].push_back({put[i].y,pn});
for(ll j=1;j<V.size();j++){
ll pr=V[j-1];
ll tr=V[j];
ll d=x[tr]-x[pr];
int nn=novi();
grana(pn,nn,d);
koji[V[j]].push_back({put[i].y,nn});
pn=nn;
}
}
for(ll i=0;i<N;i++){
for(ll j=1;j<koji[i].size();j++){
ll d=abs(koji[i][j].first-koji[i][j-1].first);
ll a=koji[i][j].second;
ll b=koji[i][j-1].second;
grana(a,b,d);
}
}
if(koji[g].size()==0 or koji[s].size()==0)
return -1;
int last=novi();
grana(last,koji[g].back().second,koji[g].back().first);
int first=novi();
grana(first,koji[s].back().second,koji[s].back().first);
dist[last]=-1;
Dijkstra(first,0);
/*
for(int i=1;i<=gsz;i++)
cout<<dist[i]<<" ";
cout<<endl;
*/
ll res=dist[last];
return res;
}
Compilation message
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:78:11: warning: statement has no effect [-Wunused-value]
78 | for(it;it!=S.end();it++){
| ^~
walk.cpp:88:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for(ll j=1;j<V.size();j++){
| ~^~~~~~~~~
walk.cpp:103:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
103 | for(ll j=1;j<koji[i].size();j++){
| ~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
121376 KB |
Output is correct |
2 |
Correct |
29 ms |
121436 KB |
Output is correct |
3 |
Correct |
29 ms |
121436 KB |
Output is correct |
4 |
Correct |
28 ms |
121436 KB |
Output is correct |
5 |
Correct |
29 ms |
121436 KB |
Output is correct |
6 |
Correct |
29 ms |
121592 KB |
Output is correct |
7 |
Correct |
28 ms |
121432 KB |
Output is correct |
8 |
Correct |
28 ms |
121440 KB |
Output is correct |
9 |
Correct |
30 ms |
121420 KB |
Output is correct |
10 |
Correct |
30 ms |
121592 KB |
Output is correct |
11 |
Correct |
30 ms |
121436 KB |
Output is correct |
12 |
Correct |
28 ms |
121432 KB |
Output is correct |
13 |
Correct |
29 ms |
121436 KB |
Output is correct |
14 |
Correct |
28 ms |
121432 KB |
Output is correct |
15 |
Correct |
29 ms |
121436 KB |
Output is correct |
16 |
Correct |
28 ms |
121436 KB |
Output is correct |
17 |
Correct |
29 ms |
121504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
121432 KB |
Output is correct |
2 |
Correct |
31 ms |
121416 KB |
Output is correct |
3 |
Correct |
703 ms |
199772 KB |
Output is correct |
4 |
Correct |
753 ms |
208120 KB |
Output is correct |
5 |
Correct |
391 ms |
191824 KB |
Output is correct |
6 |
Correct |
334 ms |
183636 KB |
Output is correct |
7 |
Correct |
370 ms |
192080 KB |
Output is correct |
8 |
Correct |
885 ms |
219348 KB |
Output is correct |
9 |
Correct |
476 ms |
195924 KB |
Output is correct |
10 |
Correct |
993 ms |
239316 KB |
Output is correct |
11 |
Correct |
427 ms |
165964 KB |
Output is correct |
12 |
Correct |
291 ms |
150100 KB |
Output is correct |
13 |
Correct |
848 ms |
226992 KB |
Output is correct |
14 |
Correct |
187 ms |
148108 KB |
Output is correct |
15 |
Correct |
212 ms |
154404 KB |
Output is correct |
16 |
Correct |
220 ms |
154704 KB |
Output is correct |
17 |
Correct |
214 ms |
153936 KB |
Output is correct |
18 |
Correct |
158 ms |
152892 KB |
Output is correct |
19 |
Correct |
37 ms |
122972 KB |
Output is correct |
20 |
Correct |
101 ms |
136768 KB |
Output is correct |
21 |
Correct |
182 ms |
152044 KB |
Output is correct |
22 |
Correct |
197 ms |
153276 KB |
Output is correct |
23 |
Correct |
239 ms |
161348 KB |
Output is correct |
24 |
Correct |
219 ms |
153924 KB |
Output is correct |
25 |
Correct |
201 ms |
153940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
135504 KB |
Output is correct |
2 |
Runtime error |
1121 ms |
821388 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
135504 KB |
Output is correct |
2 |
Runtime error |
1121 ms |
821388 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
121376 KB |
Output is correct |
2 |
Correct |
29 ms |
121436 KB |
Output is correct |
3 |
Correct |
29 ms |
121436 KB |
Output is correct |
4 |
Correct |
28 ms |
121436 KB |
Output is correct |
5 |
Correct |
29 ms |
121436 KB |
Output is correct |
6 |
Correct |
29 ms |
121592 KB |
Output is correct |
7 |
Correct |
28 ms |
121432 KB |
Output is correct |
8 |
Correct |
28 ms |
121440 KB |
Output is correct |
9 |
Correct |
30 ms |
121420 KB |
Output is correct |
10 |
Correct |
30 ms |
121592 KB |
Output is correct |
11 |
Correct |
30 ms |
121436 KB |
Output is correct |
12 |
Correct |
28 ms |
121432 KB |
Output is correct |
13 |
Correct |
29 ms |
121436 KB |
Output is correct |
14 |
Correct |
28 ms |
121432 KB |
Output is correct |
15 |
Correct |
29 ms |
121436 KB |
Output is correct |
16 |
Correct |
28 ms |
121436 KB |
Output is correct |
17 |
Correct |
29 ms |
121504 KB |
Output is correct |
18 |
Correct |
28 ms |
121432 KB |
Output is correct |
19 |
Correct |
31 ms |
121416 KB |
Output is correct |
20 |
Correct |
703 ms |
199772 KB |
Output is correct |
21 |
Correct |
753 ms |
208120 KB |
Output is correct |
22 |
Correct |
391 ms |
191824 KB |
Output is correct |
23 |
Correct |
334 ms |
183636 KB |
Output is correct |
24 |
Correct |
370 ms |
192080 KB |
Output is correct |
25 |
Correct |
885 ms |
219348 KB |
Output is correct |
26 |
Correct |
476 ms |
195924 KB |
Output is correct |
27 |
Correct |
993 ms |
239316 KB |
Output is correct |
28 |
Correct |
427 ms |
165964 KB |
Output is correct |
29 |
Correct |
291 ms |
150100 KB |
Output is correct |
30 |
Correct |
848 ms |
226992 KB |
Output is correct |
31 |
Correct |
187 ms |
148108 KB |
Output is correct |
32 |
Correct |
212 ms |
154404 KB |
Output is correct |
33 |
Correct |
220 ms |
154704 KB |
Output is correct |
34 |
Correct |
214 ms |
153936 KB |
Output is correct |
35 |
Correct |
158 ms |
152892 KB |
Output is correct |
36 |
Correct |
37 ms |
122972 KB |
Output is correct |
37 |
Correct |
101 ms |
136768 KB |
Output is correct |
38 |
Correct |
182 ms |
152044 KB |
Output is correct |
39 |
Correct |
197 ms |
153276 KB |
Output is correct |
40 |
Correct |
239 ms |
161348 KB |
Output is correct |
41 |
Correct |
219 ms |
153924 KB |
Output is correct |
42 |
Correct |
201 ms |
153940 KB |
Output is correct |
43 |
Correct |
98 ms |
135504 KB |
Output is correct |
44 |
Runtime error |
1121 ms |
821388 KB |
Execution killed with signal 6 |
45 |
Halted |
0 ms |
0 KB |
- |