# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
778529 |
2023-07-10T11:44:08 Z |
Elias |
Sky Walking (IOI19_walk) |
C++17 |
|
4000 ms |
765592 KB |
#ifndef _DEBUG
#include "walk.h"
#endif
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
struct Bridge
{
int l, r, h;
bool operator<(Bridge other)
{
return vector<int>{l, r, h} < vector<int>{other.l, other.r, other.h};
}
};
long long min_distance(std::vector<signed> x, std::vector<signed> h, std::vector<signed> l, std::vector<signed> r, std::vector<signed> y, signed s, signed g)
{
map<pair<int, int>, vector<pair<int, pair<int, int>>>> adj;
vector<Bridge> bridges;
for (int i = 0; i < l.size(); i++)
{
bridges.push_back({x[l[i]], x[r[i]], y[i]});
}
sort(bridges.begin(), bridges.end());
reverse(bridges.begin(), bridges.end());
set<pair<int, int>> active;
set<pair<int, int>> active_by_h;
map<int, int> last_at_height;
int i = 0;
for (int b : x)
{
while (active.size() && active.begin()->first < b)
{
active_by_h.erase({active.begin()->second, active.begin()->first});
active.erase(active.begin());
}
for (auto [H, end] : active_by_h)
{
if (H > h[i])
break;
int last = last_at_height[H];
adj[{b, H}].push_back({abs(last - b), {last, H}});
adj[{last, H}].push_back({abs(last - b), {b, H}});
}
while (bridges.size() && bridges.back().l == b)
{
assert(bridges.back().h <= h[i]);
active.insert({bridges.back().r, bridges.back().h});
active_by_h.insert({bridges.back().h, bridges.back().r});
bridges.pop_back();
}
int lasth = 0;
for (auto [H, end] : active_by_h)
{
if (H > h[i])
break;
adj[{b, lasth}].push_back({abs(H - lasth), {b, H}});
adj[{b, H}].push_back({abs(H - lasth), {b, lasth}});
lasth = H;
last_at_height[H] = b;
}
i++;
}
assert(bridges.size() == 0);
priority_queue<tuple<int, int, int>> pq;
pq.push(tuple<int, int, int>{0, x[s], 0});
map<pair<int, int>, int> dist;
while (pq.size())
{
auto [d, px, py] = pq.top();
pq.pop();
if (dist.count({px, py}))
continue;
dist[{px, py}] = -d;
for (auto [plusd, c] : adj[{px, py}])
{
if (dist.count(c) == 0)
pq.push(tuple<int, int, int>{d - plusd, c.first, c.second});
}
}
if (dist.count({x[g], 0}) == 0)
return -1;
return dist[{x[g], 0}];
}
#ifdef _DEBUG
signed main()
{
signed n, m;
assert(2 == scanf("%d%d", &n, &m));
vector<signed> x(n), h(n);
for (signed i = 0; i < n; i++)
assert(2 == scanf("%d%d", &x[i], &h[i]));
vector<signed> l(m), r(m), y(m);
for (signed i = 0; i < m; i++)
assert(3 == scanf("%d%d%d", &l[i], &r[i], &y[i]));
signed s, g;
assert(2 == scanf("%d%d", &s, &g));
fclose(stdin);
long long result = min_distance(x, h, l, r, y, s, g);
cerr << result << "\n";
fclose(stdout);
return 0;
}
#endif
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:25:20: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for (int i = 0; i < l.size(); i++)
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
428 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 |
428 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
304 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
2048 ms |
189092 KB |
Output is correct |
4 |
Correct |
1507 ms |
204236 KB |
Output is correct |
5 |
Correct |
674 ms |
133428 KB |
Output is correct |
6 |
Correct |
609 ms |
118240 KB |
Output is correct |
7 |
Correct |
693 ms |
133464 KB |
Output is correct |
8 |
Correct |
2608 ms |
240640 KB |
Output is correct |
9 |
Correct |
827 ms |
143532 KB |
Output is correct |
10 |
Correct |
2137 ms |
283116 KB |
Output is correct |
11 |
Correct |
821 ms |
108060 KB |
Output is correct |
12 |
Correct |
466 ms |
79332 KB |
Output is correct |
13 |
Correct |
1752 ms |
249396 KB |
Output is correct |
14 |
Correct |
325 ms |
57320 KB |
Output is correct |
15 |
Correct |
438 ms |
74008 KB |
Output is correct |
16 |
Correct |
415 ms |
74288 KB |
Output is correct |
17 |
Correct |
411 ms |
71360 KB |
Output is correct |
18 |
Correct |
526 ms |
80300 KB |
Output is correct |
19 |
Correct |
18 ms |
3992 KB |
Output is correct |
20 |
Correct |
266 ms |
38376 KB |
Output is correct |
21 |
Correct |
381 ms |
68352 KB |
Output is correct |
22 |
Correct |
476 ms |
72220 KB |
Output is correct |
23 |
Correct |
705 ms |
97264 KB |
Output is correct |
24 |
Correct |
426 ms |
72712 KB |
Output is correct |
25 |
Correct |
360 ms |
70708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
128 ms |
24000 KB |
Output is correct |
2 |
Execution timed out |
4051 ms |
765592 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
128 ms |
24000 KB |
Output is correct |
2 |
Execution timed out |
4051 ms |
765592 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
428 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 |
428 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
304 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
2048 ms |
189092 KB |
Output is correct |
21 |
Correct |
1507 ms |
204236 KB |
Output is correct |
22 |
Correct |
674 ms |
133428 KB |
Output is correct |
23 |
Correct |
609 ms |
118240 KB |
Output is correct |
24 |
Correct |
693 ms |
133464 KB |
Output is correct |
25 |
Correct |
2608 ms |
240640 KB |
Output is correct |
26 |
Correct |
827 ms |
143532 KB |
Output is correct |
27 |
Correct |
2137 ms |
283116 KB |
Output is correct |
28 |
Correct |
821 ms |
108060 KB |
Output is correct |
29 |
Correct |
466 ms |
79332 KB |
Output is correct |
30 |
Correct |
1752 ms |
249396 KB |
Output is correct |
31 |
Correct |
325 ms |
57320 KB |
Output is correct |
32 |
Correct |
438 ms |
74008 KB |
Output is correct |
33 |
Correct |
415 ms |
74288 KB |
Output is correct |
34 |
Correct |
411 ms |
71360 KB |
Output is correct |
35 |
Correct |
526 ms |
80300 KB |
Output is correct |
36 |
Correct |
18 ms |
3992 KB |
Output is correct |
37 |
Correct |
266 ms |
38376 KB |
Output is correct |
38 |
Correct |
381 ms |
68352 KB |
Output is correct |
39 |
Correct |
476 ms |
72220 KB |
Output is correct |
40 |
Correct |
705 ms |
97264 KB |
Output is correct |
41 |
Correct |
426 ms |
72712 KB |
Output is correct |
42 |
Correct |
360 ms |
70708 KB |
Output is correct |
43 |
Correct |
128 ms |
24000 KB |
Output is correct |
44 |
Execution timed out |
4051 ms |
765592 KB |
Time limit exceeded |
45 |
Halted |
0 ms |
0 KB |
- |