#include "walk.h"
#include<bits/stdc++.h>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T>
using matrix = vector<vector<T>>;
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 from, int to) {
int n = x.size();
int m = l.size();
int nodes = n;
matrix<pii> lines;
for(int i = 0; i < n; i++)
lines.push_back({{0,i}});
set<int> s;
vector<int> obuild(n), oline(m);
iota(all(obuild),0);
iota(all(oline),0);
sort(all(obuild),[&](int a, int b){
return h[a] > h[b];
});
sort(all(oline),[&](int a, int b){
return y[a] > y[b];
});
int ptr = 0;
for(int i : oline){
while(ptr < n && h[obuild[ptr]] >= y[i])
s.insert(obuild[ptr]), ptr++;
vector<int> adj;
auto it = s.lower_bound(l[i]);
while(it!=s.end() && *it <= r[i])
adj.push_back(*it), it++;
vector<pii> hor;
for(int i = 0; i < adj.size(); i++){
hor.push_back({x[adj[i]],nodes+i});
}
lines.push_back(hor);
for(int j = 0; j < adj.size(); j++){
//cout << nodes+j << " = " << "(" << x[adj[j]] << ',' << y[i] << ")\n";
lines[adj[j]].push_back({y[i],nodes+j});
}
nodes+=adj.size();
}
matrix<pii> g(nodes);
for(auto& i : lines){
sort(all(i));
for(int j = 1; j < i.size(); j++){
int peso = i[j].ff-i[j-1].ff;
g[i[j-1].ss].push_back({i[j].ss,peso});
g[i[j].ss].push_back({i[j-1].ss,peso});
}
}
vector<ll> dist(nodes,1ll<<60);
dist[from] = 0;
priority_queue<pll,vector<pll>,greater<pll>> pq;
pq.push({0,from});
while(!pq.empty()){
int cur = pq.top().ss;
int curp = pq.top().ff;
pq.pop();
if(curp > dist[cur])
continue;
for(auto [viz,peso] : g[cur]){
if(dist[viz] > dist[cur]+peso){
dist[viz] = dist[cur]+peso;
pq.push({dist[viz],viz});
}
}
}
// for(int i = 0; i < nodes; i++)
// cout << "->" << i << ": " << dist[i] << '\n';
if(dist[to] == (1ll<<60))
return -1;
return dist[to];
}
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:47:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int i = 0; i < adj.size(); i++){
| ~~^~~~~~~~~~~~
walk.cpp:52:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int j = 0; j < adj.size(); j++){
| ~~^~~~~~~~~~~~
walk.cpp:64:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int>, std::allocator<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int j = 1; j < i.size(); j++){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
260 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
300 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
292 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
593 ms |
84052 KB |
Output is correct |
4 |
Correct |
802 ms |
101664 KB |
Output is correct |
5 |
Correct |
494 ms |
88228 KB |
Output is correct |
6 |
Correct |
514 ms |
80244 KB |
Output is correct |
7 |
Correct |
490 ms |
88256 KB |
Output is correct |
8 |
Correct |
727 ms |
104320 KB |
Output is correct |
9 |
Correct |
611 ms |
86612 KB |
Output is correct |
10 |
Correct |
1002 ms |
133280 KB |
Output is correct |
11 |
Correct |
389 ms |
52596 KB |
Output is correct |
12 |
Correct |
371 ms |
49760 KB |
Output is correct |
13 |
Correct |
971 ms |
119736 KB |
Output is correct |
14 |
Correct |
240 ms |
46516 KB |
Output is correct |
15 |
Correct |
262 ms |
49108 KB |
Output is correct |
16 |
Correct |
270 ms |
47472 KB |
Output is correct |
17 |
Correct |
253 ms |
46012 KB |
Output is correct |
18 |
Correct |
147 ms |
42468 KB |
Output is correct |
19 |
Correct |
8 ms |
2576 KB |
Output is correct |
20 |
Correct |
99 ms |
23932 KB |
Output is correct |
21 |
Correct |
274 ms |
42460 KB |
Output is correct |
22 |
Correct |
307 ms |
49108 KB |
Output is correct |
23 |
Correct |
242 ms |
56076 KB |
Output is correct |
24 |
Correct |
284 ms |
47636 KB |
Output is correct |
25 |
Correct |
287 ms |
45768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
16280 KB |
Output is correct |
2 |
Correct |
3085 ms |
520680 KB |
Output is correct |
3 |
Runtime error |
2269 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
16280 KB |
Output is correct |
2 |
Correct |
3085 ms |
520680 KB |
Output is correct |
3 |
Runtime error |
2269 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
260 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
300 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
292 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
593 ms |
84052 KB |
Output is correct |
21 |
Correct |
802 ms |
101664 KB |
Output is correct |
22 |
Correct |
494 ms |
88228 KB |
Output is correct |
23 |
Correct |
514 ms |
80244 KB |
Output is correct |
24 |
Correct |
490 ms |
88256 KB |
Output is correct |
25 |
Correct |
727 ms |
104320 KB |
Output is correct |
26 |
Correct |
611 ms |
86612 KB |
Output is correct |
27 |
Correct |
1002 ms |
133280 KB |
Output is correct |
28 |
Correct |
389 ms |
52596 KB |
Output is correct |
29 |
Correct |
371 ms |
49760 KB |
Output is correct |
30 |
Correct |
971 ms |
119736 KB |
Output is correct |
31 |
Correct |
240 ms |
46516 KB |
Output is correct |
32 |
Correct |
262 ms |
49108 KB |
Output is correct |
33 |
Correct |
270 ms |
47472 KB |
Output is correct |
34 |
Correct |
253 ms |
46012 KB |
Output is correct |
35 |
Correct |
147 ms |
42468 KB |
Output is correct |
36 |
Correct |
8 ms |
2576 KB |
Output is correct |
37 |
Correct |
99 ms |
23932 KB |
Output is correct |
38 |
Correct |
274 ms |
42460 KB |
Output is correct |
39 |
Correct |
307 ms |
49108 KB |
Output is correct |
40 |
Correct |
242 ms |
56076 KB |
Output is correct |
41 |
Correct |
284 ms |
47636 KB |
Output is correct |
42 |
Correct |
287 ms |
45768 KB |
Output is correct |
43 |
Correct |
92 ms |
16280 KB |
Output is correct |
44 |
Correct |
3085 ms |
520680 KB |
Output is correct |
45 |
Runtime error |
2269 ms |
1048576 KB |
Execution killed with signal 9 |
46 |
Halted |
0 ms |
0 KB |
- |