# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
736950 |
2023-05-06T11:38:26 Z |
finn__ |
Sky Walking (IOI19_walk) |
C++17 |
|
1150 ms |
137724 KB |
#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
using L = long long;
vector<size_t> last_node;
vector<vector<pair<size_t, L>>> G;
vector<pair<L, L>> p;
vector<L> d;
vector<pair<size_t, bool>> events;
L min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r,
vector<int> y, int s, int g)
{
size_t const n = x.size(), m = l.size();
last_node.resize(m);
fill(last_node.begin(), last_node.end(), SIZE_MAX);
for (size_t i = 0; i < m; ++i)
events.emplace_back(i, 0), events.emplace_back(i, 1);
sort(events.begin(), events.end(), [&](auto const &u, auto const &v)
{ int const a = u.second ? r[u.first] : l[u.first],
b = v.second ? r[v.first] : l[v.first];
return a == b ? !u.second && v.second : a < b; });
auto compare_segment_height = [&](size_t const &i, size_t const &j)
{ return y[i] < y[j]; };
multiset<size_t, decltype(compare_segment_height)> segments(compare_segment_height);
map<pair<L, L>, size_t> nodes;
auto get_node = [&](L const &i, L const &j)
{
auto it = nodes.find({i, j});
if (it != nodes.end())
return it->second;
nodes[{i, j}] = G.size();
p.emplace_back(i, j);
G.emplace_back();
return G.size() - 1;
};
for (auto const &[i, b] : events)
{
size_t const curr_node = get_node(b ? x[r[i]] : x[l[i]], y[i]);
if (last_node[i] != SIZE_MAX)
{
G[curr_node].emplace_back(last_node[i], p[curr_node].first - p[last_node[i]].first);
G[last_node[i]].emplace_back(curr_node, p[curr_node].first - p[last_node[i]].first);
}
last_node[i] = curr_node;
if (b)
segments.erase(segments.find(i));
auto it = segments.upper_bound(i);
if (it != segments.end() && h[b ? r[i] : l[i]] >= y[*it])
{
size_t const neighbor = get_node(b ? x[r[i]] : x[l[i]], y[*it]);
G[curr_node].emplace_back(neighbor, y[*it] - y[i]);
G[neighbor].emplace_back(curr_node, y[*it] - y[i]);
G[neighbor].emplace_back(last_node[*it], p[neighbor].first - p[last_node[*it]].first);
G[last_node[*it]].emplace_back(neighbor, p[neighbor].first - p[last_node[*it]].first);
last_node[*it] = neighbor;
}
it = segments.lower_bound(i);
if (!segments.empty() && it != segments.begin() && y[*prev(it)] < y[i])
{
--it;
size_t const neighbor = get_node(b ? x[r[i]] : x[l[i]], y[*it]);
G[curr_node].emplace_back(neighbor, y[i] - y[*it]);
G[neighbor].emplace_back(curr_node, y[i] - y[*it]);
G[neighbor].emplace_back(last_node[*it], p[neighbor].first - p[last_node[*it]].first);
G[last_node[*it]].emplace_back(neighbor, p[neighbor].first - p[last_node[*it]].first);
last_node[*it] = neighbor;
}
if (!b)
segments.insert(i);
}
priority_queue<pair<L, size_t>> q;
d.resize(G.size());
fill(d.begin(), d.end(), LLONG_MAX);
for (size_t i = 0; i < G.size(); ++i)
if (p[i].first == x[s])
d[i] = p[i].second, q.emplace(-d[i], i);
while (!q.empty())
{
auto const [f, u] = q.top();
q.pop();
if (-f != d[u])
continue;
for (auto const &[v, w] : G[u])
if (-f + w < d[v])
{
d[v] = -f + w;
q.emplace(-d[v], v);
}
}
L min_distance = LLONG_MAX;
for (size_t i = 0; i < G.size(); ++i)
if (p[i].first == x[g] && d[i] != LLONG_MAX)
min_distance = min(min_distance, d[i] + p[i].second);
return min_distance == LLONG_MAX ? -1 : min_distance;
}
Compilation message
walk.cpp: In function 'L min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:15:18: warning: unused variable 'n' [-Wunused-variable]
15 | size_t const n = x.size(), m = l.size();
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
29524 KB |
Output is correct |
2 |
Correct |
821 ms |
118536 KB |
Output is correct |
3 |
Correct |
766 ms |
121956 KB |
Output is correct |
4 |
Correct |
762 ms |
125516 KB |
Output is correct |
5 |
Correct |
1138 ms |
137724 KB |
Output is correct |
6 |
Correct |
1036 ms |
125172 KB |
Output is correct |
7 |
Correct |
298 ms |
65396 KB |
Output is correct |
8 |
Correct |
246 ms |
62252 KB |
Output is correct |
9 |
Correct |
980 ms |
120488 KB |
Output is correct |
10 |
Correct |
451 ms |
84760 KB |
Output is correct |
11 |
Correct |
10 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
29524 KB |
Output is correct |
2 |
Correct |
821 ms |
118536 KB |
Output is correct |
3 |
Correct |
766 ms |
121956 KB |
Output is correct |
4 |
Correct |
762 ms |
125516 KB |
Output is correct |
5 |
Correct |
1138 ms |
137724 KB |
Output is correct |
6 |
Correct |
1036 ms |
125172 KB |
Output is correct |
7 |
Correct |
298 ms |
65396 KB |
Output is correct |
8 |
Correct |
246 ms |
62252 KB |
Output is correct |
9 |
Correct |
980 ms |
120488 KB |
Output is correct |
10 |
Correct |
451 ms |
84760 KB |
Output is correct |
11 |
Correct |
10 ms |
1876 KB |
Output is correct |
12 |
Correct |
767 ms |
121528 KB |
Output is correct |
13 |
Correct |
633 ms |
125140 KB |
Output is correct |
14 |
Correct |
1012 ms |
137700 KB |
Output is correct |
15 |
Correct |
553 ms |
95952 KB |
Output is correct |
16 |
Correct |
648 ms |
110152 KB |
Output is correct |
17 |
Correct |
728 ms |
126496 KB |
Output is correct |
18 |
Correct |
647 ms |
96056 KB |
Output is correct |
19 |
Correct |
720 ms |
110308 KB |
Output is correct |
20 |
Correct |
374 ms |
64156 KB |
Output is correct |
21 |
Correct |
25 ms |
4940 KB |
Output is correct |
22 |
Correct |
402 ms |
97192 KB |
Output is correct |
23 |
Correct |
382 ms |
91896 KB |
Output is correct |
24 |
Correct |
293 ms |
64592 KB |
Output is correct |
25 |
Correct |
324 ms |
84688 KB |
Output is correct |
26 |
Correct |
227 ms |
47684 KB |
Output is correct |
27 |
Correct |
1150 ms |
136080 KB |
Output is correct |
28 |
Correct |
619 ms |
123432 KB |
Output is correct |
29 |
Correct |
1061 ms |
125280 KB |
Output is correct |
30 |
Correct |
302 ms |
65128 KB |
Output is correct |
31 |
Correct |
1008 ms |
120276 KB |
Output is correct |
32 |
Correct |
341 ms |
75468 KB |
Output is correct |
33 |
Correct |
306 ms |
72716 KB |
Output is correct |
34 |
Correct |
453 ms |
77388 KB |
Output is correct |
35 |
Correct |
361 ms |
80080 KB |
Output is correct |
36 |
Correct |
275 ms |
67016 KB |
Output is correct |
37 |
Correct |
221 ms |
66840 KB |
Output is correct |
38 |
Correct |
257 ms |
61388 KB |
Output is correct |
39 |
Correct |
509 ms |
73780 KB |
Output is correct |
40 |
Correct |
267 ms |
63928 KB |
Output is correct |
41 |
Correct |
218 ms |
60708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |