#include <bits/stdc++.h>
#include "walk.h"
#pragma GCC optimize("O3")
#define ll long long
using namespace std;
const int N = 100000;
const ll INF = numeric_limits<ll>::max()/4;
int n, m, s, e;
int x[N], h[N], l[N], r[N], y[N];
ll st1(){
int c = n;
vector< pair<int, int> > last(n, {-1, -1});
vector< vector< pair<int, ll> > > g(c);
vector< tuple<int, int, int> > sky(m);
for(int i = 0; i < m; i++) sky[i] = {y[i], l[i], r[i]};
sort(sky.rbegin(), sky.rend());
set<int> building;
vector< pair<int, int> > build(n);
for(int i = 0; i < n; i++) build[i] = {h[i], i};
sort(build.begin(), build.end());
for(int i = 0; i < m; i++){
while(!build.empty() && build.back().first >= get<0>(sky[i]))
building.insert(build.back().second), build.pop_back();
auto it = building.lower_bound(get<1>(sky[i]));
int prev = -1, ind;
while(it != building.end() && *it <= get<2>(sky[i])){
int pos = *it, hi = get<0>(sky[i]);
it++;
g.resize(c+1);
if(last[pos].first != -1){
g[last[pos].first].push_back({c, last[pos].second-hi});
g[c].push_back({last[pos].first, last[pos].second-hi});
}
last[pos] = {c, hi};
if(prev != -1){
g[ind].push_back({c, x[pos]-x[prev]});
g[c].push_back({ind, x[pos]-x[prev]});
}
prev = pos, ind = c;
c++;
}
}
for(int i = 0; i < n; i++){
if(last[i].first != -1){
g[i].push_back({last[i].first, last[i].second});
g[last[i].first].push_back({i, last[i].second});
}
}
vector<ll> dis(c, INF);
vector<int> vis(c);
priority_queue< pair<ll, int>, vector< pair<ll, int> >, greater< pair<ll, int> > > q;
dis[s] = 0;
q.push({0, s});
while(!q.empty()){
int u = q.top().second, v;
ll w;
q.pop();
if(vis[u]) continue;
vis[u] = 1;
if(u == e) return dis[u];
for(auto &t : g[u]){
tie(v, w) = t;
if(dis[v] > dis[u]+w){
dis[v] = dis[u]+w;
q.push({dis[v], v});
}
}
}
return -1;
}
void wrt(vector<int>& X, vector<int>& H, vector<int>& L, vector<int>& R, vector<int>& Y, int S, int G){
for(int i = 0; i < n; i++) x[i] = X[i], h[i] = H[i];
for(int i = 0; i < m; i++) l[i] = L[i], r[i] = R[i], y[i] = Y[i];
s = S, e = G;
}
ll min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r, vector<int> y, int s, int g){
n = x.size(), m = y.size();
wrt(x, h, l, r, y, s, g);
return st1();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
375 ms |
85864 KB |
Output is correct |
4 |
Correct |
897 ms |
108060 KB |
Output is correct |
5 |
Correct |
668 ms |
90124 KB |
Output is correct |
6 |
Correct |
641 ms |
81352 KB |
Output is correct |
7 |
Correct |
538 ms |
90180 KB |
Output is correct |
8 |
Correct |
537 ms |
110824 KB |
Output is correct |
9 |
Correct |
706 ms |
88380 KB |
Output is correct |
10 |
Correct |
1119 ms |
137320 KB |
Output is correct |
11 |
Correct |
408 ms |
53300 KB |
Output is correct |
12 |
Correct |
452 ms |
45052 KB |
Output is correct |
13 |
Correct |
1010 ms |
121828 KB |
Output is correct |
14 |
Correct |
314 ms |
42796 KB |
Output is correct |
15 |
Correct |
266 ms |
44052 KB |
Output is correct |
16 |
Correct |
238 ms |
43908 KB |
Output is correct |
17 |
Correct |
241 ms |
42448 KB |
Output is correct |
18 |
Correct |
171 ms |
41340 KB |
Output is correct |
19 |
Correct |
11 ms |
2460 KB |
Output is correct |
20 |
Correct |
113 ms |
22084 KB |
Output is correct |
21 |
Correct |
195 ms |
40408 KB |
Output is correct |
22 |
Correct |
205 ms |
43668 KB |
Output is correct |
23 |
Correct |
287 ms |
52632 KB |
Output is correct |
24 |
Correct |
227 ms |
43404 KB |
Output is correct |
25 |
Correct |
250 ms |
42612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
16456 KB |
Output is correct |
2 |
Correct |
2867 ms |
587600 KB |
Output is correct |
3 |
Runtime error |
2695 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
16456 KB |
Output is correct |
2 |
Correct |
2867 ms |
587600 KB |
Output is correct |
3 |
Runtime error |
2695 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
375 ms |
85864 KB |
Output is correct |
21 |
Correct |
897 ms |
108060 KB |
Output is correct |
22 |
Correct |
668 ms |
90124 KB |
Output is correct |
23 |
Correct |
641 ms |
81352 KB |
Output is correct |
24 |
Correct |
538 ms |
90180 KB |
Output is correct |
25 |
Correct |
537 ms |
110824 KB |
Output is correct |
26 |
Correct |
706 ms |
88380 KB |
Output is correct |
27 |
Correct |
1119 ms |
137320 KB |
Output is correct |
28 |
Correct |
408 ms |
53300 KB |
Output is correct |
29 |
Correct |
452 ms |
45052 KB |
Output is correct |
30 |
Correct |
1010 ms |
121828 KB |
Output is correct |
31 |
Correct |
314 ms |
42796 KB |
Output is correct |
32 |
Correct |
266 ms |
44052 KB |
Output is correct |
33 |
Correct |
238 ms |
43908 KB |
Output is correct |
34 |
Correct |
241 ms |
42448 KB |
Output is correct |
35 |
Correct |
171 ms |
41340 KB |
Output is correct |
36 |
Correct |
11 ms |
2460 KB |
Output is correct |
37 |
Correct |
113 ms |
22084 KB |
Output is correct |
38 |
Correct |
195 ms |
40408 KB |
Output is correct |
39 |
Correct |
205 ms |
43668 KB |
Output is correct |
40 |
Correct |
287 ms |
52632 KB |
Output is correct |
41 |
Correct |
227 ms |
43404 KB |
Output is correct |
42 |
Correct |
250 ms |
42612 KB |
Output is correct |
43 |
Correct |
78 ms |
16456 KB |
Output is correct |
44 |
Correct |
2867 ms |
587600 KB |
Output is correct |
45 |
Runtime error |
2695 ms |
1048576 KB |
Execution killed with signal 9 |
46 |
Halted |
0 ms |
0 KB |
- |