#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int,int>,int> > v;
vector<pair<int,long long> > adjl[1100005];
long long dist[1100005];
vector<pair<int,int> > skyh[100005];
long long 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) {
vector<pair<int,int> > news;
for (int x = 0; x<X.size(); x++){
news.push_back({h[x],x});
}
sort(news.begin(),news.end(),greater<pair<int,int> >());
set<int> S;
vector<pair<int,int> > sky;
for (int x = 0; x<l.size(); x++){
sky.push_back({y[x],x});
}
int nwn = X.size();
sort(sky.begin(),sky.end(),greater<pair<int,int> >());
int cur = 0;
for (auto x : sky){
while (cur!=X.size() && news[cur].first>=x.first){
S.insert(news[cur].second);
cur++;
}
bool isn = true;
int pre = -1;
for (auto it = S.lower_bound(l[x.second]); it!=S.end() && (*it)<=r[x.second]; it++){
int nw = nwn++;
//printf("%d is (%d,%d)\n",nw,X[(*it)],x.first);
skyh[(*it)].push_back({x.first,nw});
if (!isn){
adjl[nw].push_back({nw-1,X[(*it)]-pre});
adjl[nw-1].push_back({nw,X[(*it)]-pre});
//printf("add edge %d %d %d\n",nw,nw-1,X[(*it)]-pre);
}
pre = X[(*it)];
isn = false;
}
}
int stn,endn;
for (int x = 0; x<X.size(); x++){
if (x==s){
stn = nwn++;
skyh[x].push_back({0,stn});
}
if (x==g){
endn = nwn++;
skyh[x].push_back({0,endn});
}
sort(skyh[x].begin(),skyh[x].end());
for (int z = 1; z<skyh[x].size(); z++){
adjl[skyh[x][z].second].push_back({skyh[x][z-1].second,skyh[x][z].first-skyh[x][z-1].first});
adjl[skyh[x][z-1].second].push_back({skyh[x][z].second,skyh[x][z].first-skyh[x][z-1].first});
//printf("add edge %d-%d,%d\n",skyh[x][z-1].second,skyh[x][z].second,skyh[x][z].first-skyh[x][z-1].first);
}
}
//printf("stn,%d,endn,%d\n",stn,endn);
priority_queue<pair<long long,int>,vector<pair<long long,int> >,greater<pair<long long,int> > >pq;
memset(dist,-1,sizeof(dist));
dist[stn] = 0;
pq.push({0,stn});
while (!pq.empty()){
int nd = pq.top().second;
long long d = pq.top().first;
pq.pop();
if (d>dist[nd]) continue;
//printf("d[%d] = %d\n",nd,d);
for (auto x : adjl[nd]){
if (dist[x.first]==-1 || d+x.second<dist[x.first]){
dist[x.first] = d+x.second;
pq.push({dist[x.first],x.first});
}
}
}
if (dist[endn]==-1) return -1;
//printf("distThing = %d\n",dist[endn]);
return dist[endn];
}
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:13:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | for (int x = 0; x<X.size(); x++){
| ~^~~~~~~~~
walk.cpp:19:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for (int x = 0; x<l.size(); x++){
| ~^~~~~~~~~
walk.cpp:26:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | while (cur!=X.size() && news[cur].first>=x.first){
| ~~~^~~~~~~~~~
walk.cpp:46:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for (int x = 0; x<X.size(); x++){
| ~^~~~~~~~~
walk.cpp:56:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (int z = 1; z<skyh[x].size(); z++){
| ~^~~~~~~~~~~~~~~
walk.cpp:80:18: warning: 'endn' may be used uninitialized in this function [-Wmaybe-uninitialized]
80 | if (dist[endn]==-1) return -1;
| ~~~~~~~~~^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
37120 KB |
Output is correct |
2 |
Correct |
25 ms |
37132 KB |
Output is correct |
3 |
Correct |
25 ms |
37120 KB |
Output is correct |
4 |
Correct |
25 ms |
37112 KB |
Output is correct |
5 |
Correct |
25 ms |
37120 KB |
Output is correct |
6 |
Correct |
25 ms |
37120 KB |
Output is correct |
7 |
Correct |
26 ms |
37120 KB |
Output is correct |
8 |
Correct |
25 ms |
37112 KB |
Output is correct |
9 |
Correct |
25 ms |
37120 KB |
Output is correct |
10 |
Correct |
25 ms |
37248 KB |
Output is correct |
11 |
Correct |
25 ms |
37112 KB |
Output is correct |
12 |
Correct |
25 ms |
37120 KB |
Output is correct |
13 |
Correct |
25 ms |
37112 KB |
Output is correct |
14 |
Correct |
24 ms |
37120 KB |
Output is correct |
15 |
Correct |
26 ms |
37116 KB |
Output is correct |
16 |
Correct |
26 ms |
37120 KB |
Output is correct |
17 |
Correct |
26 ms |
37240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
37120 KB |
Output is correct |
2 |
Correct |
25 ms |
37120 KB |
Output is correct |
3 |
Correct |
751 ms |
110044 KB |
Output is correct |
4 |
Correct |
930 ms |
118888 KB |
Output is correct |
5 |
Correct |
597 ms |
108276 KB |
Output is correct |
6 |
Correct |
525 ms |
100716 KB |
Output is correct |
7 |
Correct |
592 ms |
108392 KB |
Output is correct |
8 |
Correct |
921 ms |
127960 KB |
Output is correct |
9 |
Correct |
695 ms |
107880 KB |
Output is correct |
10 |
Correct |
1199 ms |
147728 KB |
Output is correct |
11 |
Correct |
497 ms |
79600 KB |
Output is correct |
12 |
Correct |
425 ms |
67164 KB |
Output is correct |
13 |
Correct |
1075 ms |
136684 KB |
Output is correct |
14 |
Correct |
268 ms |
65768 KB |
Output is correct |
15 |
Correct |
311 ms |
65640 KB |
Output is correct |
16 |
Correct |
293 ms |
67048 KB |
Output is correct |
17 |
Correct |
324 ms |
65768 KB |
Output is correct |
18 |
Correct |
171 ms |
64812 KB |
Output is correct |
19 |
Correct |
33 ms |
38520 KB |
Output is correct |
20 |
Correct |
124 ms |
51956 KB |
Output is correct |
21 |
Correct |
317 ms |
64872 KB |
Output is correct |
22 |
Correct |
340 ms |
65772 KB |
Output is correct |
23 |
Correct |
265 ms |
75760 KB |
Output is correct |
24 |
Correct |
301 ms |
65896 KB |
Output is correct |
25 |
Correct |
342 ms |
65768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
136 ms |
50288 KB |
Output is correct |
2 |
Runtime error |
394 ms |
195184 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
136 ms |
50288 KB |
Output is correct |
2 |
Runtime error |
394 ms |
195184 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
37120 KB |
Output is correct |
2 |
Correct |
25 ms |
37132 KB |
Output is correct |
3 |
Correct |
25 ms |
37120 KB |
Output is correct |
4 |
Correct |
25 ms |
37112 KB |
Output is correct |
5 |
Correct |
25 ms |
37120 KB |
Output is correct |
6 |
Correct |
25 ms |
37120 KB |
Output is correct |
7 |
Correct |
26 ms |
37120 KB |
Output is correct |
8 |
Correct |
25 ms |
37112 KB |
Output is correct |
9 |
Correct |
25 ms |
37120 KB |
Output is correct |
10 |
Correct |
25 ms |
37248 KB |
Output is correct |
11 |
Correct |
25 ms |
37112 KB |
Output is correct |
12 |
Correct |
25 ms |
37120 KB |
Output is correct |
13 |
Correct |
25 ms |
37112 KB |
Output is correct |
14 |
Correct |
24 ms |
37120 KB |
Output is correct |
15 |
Correct |
26 ms |
37116 KB |
Output is correct |
16 |
Correct |
26 ms |
37120 KB |
Output is correct |
17 |
Correct |
26 ms |
37240 KB |
Output is correct |
18 |
Correct |
25 ms |
37120 KB |
Output is correct |
19 |
Correct |
25 ms |
37120 KB |
Output is correct |
20 |
Correct |
751 ms |
110044 KB |
Output is correct |
21 |
Correct |
930 ms |
118888 KB |
Output is correct |
22 |
Correct |
597 ms |
108276 KB |
Output is correct |
23 |
Correct |
525 ms |
100716 KB |
Output is correct |
24 |
Correct |
592 ms |
108392 KB |
Output is correct |
25 |
Correct |
921 ms |
127960 KB |
Output is correct |
26 |
Correct |
695 ms |
107880 KB |
Output is correct |
27 |
Correct |
1199 ms |
147728 KB |
Output is correct |
28 |
Correct |
497 ms |
79600 KB |
Output is correct |
29 |
Correct |
425 ms |
67164 KB |
Output is correct |
30 |
Correct |
1075 ms |
136684 KB |
Output is correct |
31 |
Correct |
268 ms |
65768 KB |
Output is correct |
32 |
Correct |
311 ms |
65640 KB |
Output is correct |
33 |
Correct |
293 ms |
67048 KB |
Output is correct |
34 |
Correct |
324 ms |
65768 KB |
Output is correct |
35 |
Correct |
171 ms |
64812 KB |
Output is correct |
36 |
Correct |
33 ms |
38520 KB |
Output is correct |
37 |
Correct |
124 ms |
51956 KB |
Output is correct |
38 |
Correct |
317 ms |
64872 KB |
Output is correct |
39 |
Correct |
340 ms |
65772 KB |
Output is correct |
40 |
Correct |
265 ms |
75760 KB |
Output is correct |
41 |
Correct |
301 ms |
65896 KB |
Output is correct |
42 |
Correct |
342 ms |
65768 KB |
Output is correct |
43 |
Correct |
136 ms |
50288 KB |
Output is correct |
44 |
Runtime error |
394 ms |
195184 KB |
Execution killed with signal 11 |
45 |
Halted |
0 ms |
0 KB |
- |