#include "walk.h"
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <iostream>
using namespace std;
long long min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r, vector<int> y, int s, int e) {
int n = x.size();
int m = l.size();
int sz = n - 1;
vector<pair<int, int>> add, now;
set<int> is;
map<int, int> can[n];
vector<vector<pair<int, int>>> g(n, vector<pair<int, int>>(0));
vector<long long> dp(n, -1);
for (int i = 0; i < m; ++i)
add.push_back({y[i], i});
for (int i = 0; i < n; ++i)
now.push_back({h[i], i});
sort(add.begin(), add.end());
reverse(add.begin(), add.end());
sort(now.begin(), now.end());
for (int i = 0; i < m; ++i) {
int j = add[i].second;
while (now.size() && now.back().first >= add[i].first) {
is.insert(now.back().second);
now.pop_back();
}
auto it = is.lower_bound(l[j]);
while (it != is.end() && *it <= r[j]) {
if (it == is.end()) break;
if (!can[*it].count(y[j])) {
can[*it][y[j]] = ++sz;
g.push_back({});
dp.push_back(-1);
}
if (it != is.begin() && *prev(it) >= l[j]) {
g[can[*it][y[j]]].push_back({can[*prev(it)][y[j]], x[*it] - x[*prev(it)]});
g[can[*prev(it)][y[j]]].push_back({can[*it][y[j]], x[*it] - x[*prev(it)]});
}
it = next(it);
}
}
for (int i = 0; i < n; ++i) {
int last = 0, pos = i;
for (auto it = can[i].begin(); it != can[i].end(); ++it) {
g[pos].push_back({it->second, it->first - last});
g[it->second].push_back({pos, it->first - last});
last = it->first;
pos = it->second;
}
}
priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> q;
q.push({0, s});
dp[s] = 0;
while (!q.empty()) {
int v = q.top().second;
long long C = q.top().first;
q.pop();
if (dp[v] < C)
continue;
for (auto [to, c] : g[v]) {
if (dp[to] == -1 || dp[to] > dp[v] + c) {
dp[to] = dp[v] + c;
q.push({dp[to], to});
}
}
}
return dp[e];
}
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:67:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
67 | for (auto [to, c] : g[v]) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
224 KB |
Output is correct |
2 |
Correct |
0 ms |
288 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
368 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1622 ms |
109968 KB |
Output is correct |
4 |
Correct |
1405 ms |
124116 KB |
Output is correct |
5 |
Correct |
872 ms |
108776 KB |
Output is correct |
6 |
Correct |
776 ms |
96440 KB |
Output is correct |
7 |
Correct |
901 ms |
108836 KB |
Output is correct |
8 |
Correct |
2106 ms |
141336 KB |
Output is correct |
9 |
Correct |
1119 ms |
105376 KB |
Output is correct |
10 |
Correct |
1975 ms |
171288 KB |
Output is correct |
11 |
Correct |
876 ms |
59880 KB |
Output is correct |
12 |
Correct |
568 ms |
44888 KB |
Output is correct |
13 |
Correct |
1778 ms |
150836 KB |
Output is correct |
14 |
Correct |
375 ms |
43360 KB |
Output is correct |
15 |
Correct |
441 ms |
44872 KB |
Output is correct |
16 |
Correct |
405 ms |
46052 KB |
Output is correct |
17 |
Correct |
409 ms |
44136 KB |
Output is correct |
18 |
Correct |
280 ms |
43800 KB |
Output is correct |
19 |
Correct |
13 ms |
2436 KB |
Output is correct |
20 |
Correct |
117 ms |
21656 KB |
Output is correct |
21 |
Correct |
443 ms |
42308 KB |
Output is correct |
22 |
Correct |
461 ms |
44932 KB |
Output is correct |
23 |
Correct |
402 ms |
55888 KB |
Output is correct |
24 |
Correct |
421 ms |
44956 KB |
Output is correct |
25 |
Correct |
468 ms |
43592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
11988 KB |
Output is correct |
2 |
Execution timed out |
4072 ms |
300312 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
11988 KB |
Output is correct |
2 |
Execution timed out |
4072 ms |
300312 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
224 KB |
Output is correct |
2 |
Correct |
0 ms |
288 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
368 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1622 ms |
109968 KB |
Output is correct |
21 |
Correct |
1405 ms |
124116 KB |
Output is correct |
22 |
Correct |
872 ms |
108776 KB |
Output is correct |
23 |
Correct |
776 ms |
96440 KB |
Output is correct |
24 |
Correct |
901 ms |
108836 KB |
Output is correct |
25 |
Correct |
2106 ms |
141336 KB |
Output is correct |
26 |
Correct |
1119 ms |
105376 KB |
Output is correct |
27 |
Correct |
1975 ms |
171288 KB |
Output is correct |
28 |
Correct |
876 ms |
59880 KB |
Output is correct |
29 |
Correct |
568 ms |
44888 KB |
Output is correct |
30 |
Correct |
1778 ms |
150836 KB |
Output is correct |
31 |
Correct |
375 ms |
43360 KB |
Output is correct |
32 |
Correct |
441 ms |
44872 KB |
Output is correct |
33 |
Correct |
405 ms |
46052 KB |
Output is correct |
34 |
Correct |
409 ms |
44136 KB |
Output is correct |
35 |
Correct |
280 ms |
43800 KB |
Output is correct |
36 |
Correct |
13 ms |
2436 KB |
Output is correct |
37 |
Correct |
117 ms |
21656 KB |
Output is correct |
38 |
Correct |
443 ms |
42308 KB |
Output is correct |
39 |
Correct |
461 ms |
44932 KB |
Output is correct |
40 |
Correct |
402 ms |
55888 KB |
Output is correct |
41 |
Correct |
421 ms |
44956 KB |
Output is correct |
42 |
Correct |
468 ms |
43592 KB |
Output is correct |
43 |
Correct |
92 ms |
11988 KB |
Output is correct |
44 |
Execution timed out |
4072 ms |
300312 KB |
Time limit exceeded |
45 |
Halted |
0 ms |
0 KB |
- |