#define BUGO(x) cerr << #x << " -> " << (x) << endl;
#include "walk.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
using llong = long long;
vector<pair<int, int>> nei[6900'000];
llong dist[6900'000];
llong Dijkstra(int s, int e)
{
const llong inf = 69'000'000'000'000'000LL;
fill(dist, dist + 6900'000, inf);
priority_queue<pair<llong, int>> q;
q.push({dist[s] = 0, s});
while (q.size())
{
int v = q.top().second;
llong d = -q.top().first;
q.pop();
if (dist[v] != d) continue;
for (auto to: nei[v])
if (d + to.second < dist[to.first])
q.push({-(dist[to.first] = d + to.second), to.first});
}
return dist[e] == inf ? -1 : dist[e];
}
map<int, int> nodeOf[100'000];
long long min_distance(std::vector<int> x, std::vector<int> y, std::vector<int> l, std::vector<int> r,
std::vector<int> h, int s, int e) {
int n = x.size();
int m = l.size();
int nodes = 0;
for (int i = 0; i < n; ++i)
nodeOf[i][y[i]] = nodes++;
nodeOf[s][0] = nodes++;
nodeOf[e][0] = nodes++;
bool smallTest = (n <= 50 && m <= 50) || y != vector<int>(n, y[0]);
vector<int> towers(n);
iota(towers.begin(), towers.end(), 0);
sort(towers.begin(), towers.end(), [&](int l, int r) {
return y[l] < y[r];
});
vector<int> bridges(m);
iota(bridges.begin(), bridges.end(), 0);
sort(bridges.begin(), bridges.end(), [&](int l, int r) {
return h[l] < h[r];
});
set<int> activeTowers;
for (int tch = m - 1; tch >= 0; --tch)
{
int j = bridges[tch];
while (towers.size() && y[towers.back()] >= h[j]) {
activeTowers.insert(towers.back());
towers.pop_back();
}
int lt = -1;
for (auto it = activeTowers.lower_bound(l[j]); it != activeTowers.end() && *it <= r[j]; )
{
int i = *it;
if (!nodeOf[i].count(h[j]))
nodeOf[i][h[j]] = nodes++;
if (lt != -1) {
int u = nodeOf[i][h[j]];
int v = nodeOf[lt][h[j]];
nei[u].push_back({v, x[i] - x[lt]});
nei[v].push_back({u, x[i] - x[lt]});
}
lt = i;
if (smallTest)
++it;
else if (*it == l[j])
it = activeTowers.lower_bound(r[j]);
else
break;
}
}
for (int i = 0; i < n; ++i)
{
int ltHei = -1;
for (auto [hei, node]: nodeOf[i])
{
if (ltHei != -1) {
int u = nodeOf[i][ltHei];
int v = node;
nei[u].push_back({v, hei - ltHei});
nei[v].push_back({u, hei - ltHei});
}
ltHei = hei;
}
}
return Dijkstra(n, n + 1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
141 ms |
220996 KB |
Output is correct |
2 |
Correct |
142 ms |
220952 KB |
Output is correct |
3 |
Correct |
138 ms |
220904 KB |
Output is correct |
4 |
Correct |
147 ms |
221036 KB |
Output is correct |
5 |
Correct |
139 ms |
221012 KB |
Output is correct |
6 |
Correct |
136 ms |
220996 KB |
Output is correct |
7 |
Correct |
140 ms |
221076 KB |
Output is correct |
8 |
Correct |
138 ms |
220992 KB |
Output is correct |
9 |
Correct |
142 ms |
220976 KB |
Output is correct |
10 |
Correct |
136 ms |
221124 KB |
Output is correct |
11 |
Correct |
139 ms |
220924 KB |
Output is correct |
12 |
Correct |
146 ms |
220968 KB |
Output is correct |
13 |
Correct |
151 ms |
220936 KB |
Output is correct |
14 |
Correct |
136 ms |
221156 KB |
Output is correct |
15 |
Correct |
141 ms |
220928 KB |
Output is correct |
16 |
Correct |
138 ms |
220996 KB |
Output is correct |
17 |
Correct |
137 ms |
221080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
143 ms |
220948 KB |
Output is correct |
2 |
Correct |
146 ms |
220924 KB |
Output is correct |
3 |
Correct |
1297 ms |
308244 KB |
Output is correct |
4 |
Correct |
1204 ms |
319556 KB |
Output is correct |
5 |
Correct |
807 ms |
306872 KB |
Output is correct |
6 |
Correct |
704 ms |
296016 KB |
Output is correct |
7 |
Correct |
825 ms |
306900 KB |
Output is correct |
8 |
Correct |
1769 ms |
335532 KB |
Output is correct |
9 |
Correct |
963 ms |
308056 KB |
Output is correct |
10 |
Correct |
1584 ms |
361008 KB |
Output is correct |
11 |
Correct |
708 ms |
270900 KB |
Output is correct |
12 |
Correct |
564 ms |
259472 KB |
Output is correct |
13 |
Correct |
1360 ms |
344844 KB |
Output is correct |
14 |
Correct |
390 ms |
253376 KB |
Output is correct |
15 |
Correct |
381 ms |
249276 KB |
Output is correct |
16 |
Correct |
386 ms |
251376 KB |
Output is correct |
17 |
Correct |
404 ms |
250324 KB |
Output is correct |
18 |
Correct |
382 ms |
255804 KB |
Output is correct |
19 |
Correct |
142 ms |
222284 KB |
Output is correct |
20 |
Correct |
222 ms |
234932 KB |
Output is correct |
21 |
Correct |
406 ms |
249500 KB |
Output is correct |
22 |
Correct |
395 ms |
249112 KB |
Output is correct |
23 |
Correct |
407 ms |
258484 KB |
Output is correct |
24 |
Correct |
417 ms |
250216 KB |
Output is correct |
25 |
Correct |
427 ms |
249892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
217 ms |
228292 KB |
Output is correct |
2 |
Incorrect |
502 ms |
244516 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
217 ms |
228292 KB |
Output is correct |
2 |
Incorrect |
502 ms |
244516 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
141 ms |
220996 KB |
Output is correct |
2 |
Correct |
142 ms |
220952 KB |
Output is correct |
3 |
Correct |
138 ms |
220904 KB |
Output is correct |
4 |
Correct |
147 ms |
221036 KB |
Output is correct |
5 |
Correct |
139 ms |
221012 KB |
Output is correct |
6 |
Correct |
136 ms |
220996 KB |
Output is correct |
7 |
Correct |
140 ms |
221076 KB |
Output is correct |
8 |
Correct |
138 ms |
220992 KB |
Output is correct |
9 |
Correct |
142 ms |
220976 KB |
Output is correct |
10 |
Correct |
136 ms |
221124 KB |
Output is correct |
11 |
Correct |
139 ms |
220924 KB |
Output is correct |
12 |
Correct |
146 ms |
220968 KB |
Output is correct |
13 |
Correct |
151 ms |
220936 KB |
Output is correct |
14 |
Correct |
136 ms |
221156 KB |
Output is correct |
15 |
Correct |
141 ms |
220928 KB |
Output is correct |
16 |
Correct |
138 ms |
220996 KB |
Output is correct |
17 |
Correct |
137 ms |
221080 KB |
Output is correct |
18 |
Correct |
143 ms |
220948 KB |
Output is correct |
19 |
Correct |
146 ms |
220924 KB |
Output is correct |
20 |
Correct |
1297 ms |
308244 KB |
Output is correct |
21 |
Correct |
1204 ms |
319556 KB |
Output is correct |
22 |
Correct |
807 ms |
306872 KB |
Output is correct |
23 |
Correct |
704 ms |
296016 KB |
Output is correct |
24 |
Correct |
825 ms |
306900 KB |
Output is correct |
25 |
Correct |
1769 ms |
335532 KB |
Output is correct |
26 |
Correct |
963 ms |
308056 KB |
Output is correct |
27 |
Correct |
1584 ms |
361008 KB |
Output is correct |
28 |
Correct |
708 ms |
270900 KB |
Output is correct |
29 |
Correct |
564 ms |
259472 KB |
Output is correct |
30 |
Correct |
1360 ms |
344844 KB |
Output is correct |
31 |
Correct |
390 ms |
253376 KB |
Output is correct |
32 |
Correct |
381 ms |
249276 KB |
Output is correct |
33 |
Correct |
386 ms |
251376 KB |
Output is correct |
34 |
Correct |
404 ms |
250324 KB |
Output is correct |
35 |
Correct |
382 ms |
255804 KB |
Output is correct |
36 |
Correct |
142 ms |
222284 KB |
Output is correct |
37 |
Correct |
222 ms |
234932 KB |
Output is correct |
38 |
Correct |
406 ms |
249500 KB |
Output is correct |
39 |
Correct |
395 ms |
249112 KB |
Output is correct |
40 |
Correct |
407 ms |
258484 KB |
Output is correct |
41 |
Correct |
417 ms |
250216 KB |
Output is correct |
42 |
Correct |
427 ms |
249892 KB |
Output is correct |
43 |
Correct |
217 ms |
228292 KB |
Output is correct |
44 |
Incorrect |
502 ms |
244516 KB |
Output isn't correct |
45 |
Halted |
0 ms |
0 KB |
- |