# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1024035 |
2024-07-15T10:43:16 Z |
c2zi6 |
Sky Walking (IOI19_walk) |
C++14 |
|
4000 ms |
510980 KB |
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "walk.h"
struct BRIDGE {
int l, r, y;
};
struct BUILDING {
int x, h;
};
namespace TEST4 {
struct SEGTREE {
int n;
VI tree;
VI lazy;
SEGTREE(int sz) {
n = 1;
while (n < sz) n *= 2;
lazy = tree = VI(2*n, -1);
}
void push(int N) {
if (lazy[N] == -1) return;
tree[N] = lazy[N];
if (N <= n-2) {
lazy[2*N+1] = lazy[N];
lazy[2*N+2] = lazy[N];
}
lazy[N] = -1;
}
int get(int N, int L, int R, int l, int r) {
push(N);
if (l <= L && R <= r) return tree[N];
if (R < l || L > r) return -1;
int M = (L + R) / 2;
return max(get(2*N+1, L, M, l, r), get(2*N+2, M+1, R, l, r));
}
void upd(int N, int L, int R, int l, int r, int s) {
push(N);
if (R < l || L > r) return;
if (l <= L && R <= r) {
lazy[N] = s;
push(N);
return;
}
int M = (L + R) / 2;
upd(2*N+1, L, M, l, r, s);
upd(2*N+2, M+1, R, l, r, s);
tree[N] = max(tree[2*N+1], tree[2*N+2]);
}
int get(int l, int r) {
return get(0, 0, n-1, l, r);
}
int get(int i) {
return get(0, 0, n-1, i, i);
}
void upd(int l, int r, int s) {
upd(0, 0, n-1, l, r, s);
}
};
};
ll min_distance(VI X, VI H, VI L, VI R, VI Y, int S, int T) {
vector<BUILDING> buildings(X.size());
rep(i, X.size()) buildings[i] = {X[i], H[i]};
vector<BRIDGE> bridges(L.size());
rep(i, L.size()) bridges[i] = {L[i], R[i], Y[i]};
map<PII, int> ind;
VPI point;
VVPI gp;
auto addvertex = [&](int x, int y) {
if (ind.count({x, y})) return;
ind[{x, y}] = gp.size();
point.pb({x, y});
gp.pb(VPI());
};
if (S == 0 && T == X.size()-1) {
/*TEST 4 */
addvertex(0, 0);
addvertex(X.size()-1, 0);
/* vertical */
sort(all(bridges), [](const BRIDGE& a, const BRIDGE& b){return a.y < b.y;});
TEST4::SEGTREE seg(X.size());
seg.upd(0, 0, 0);
seg.upd(X.size()-1, X.size()-1, 0);
for (auto&[l, r, y] : bridges) {
addvertex(l, y);
addvertex(r, y);
for (int x : {l, r}) {
int vy = seg.get(x);
if (vy == -1) continue;
addvertex(x, vy);
int u = ind[{x, y}];
int v = ind[{x, vy}];
int w = y - vy;
gp[u].pb({v, w});
gp[v].pb({u, w});
}
seg.upd(l, r, y);
}
/* horizontal */
VPI pts = point;
sort(all(pts), [](const PII& a, const PII& b){return mkp(a.ss, a.ff) < mkp(b.ss, b.ff);});
int j = 0;
VI layer;
for (int i = 0; i < bridges.size(); i++) {
if (i == 0 || bridges[i].y != bridges[i-1].y) {
layer = VI();
while (j != pts.size() && pts[j].ss < bridges[i].y) j++;
while (j != pts.size() && pts[j].ss == bridges[i].y) layer.pb(pts[j++].ff);
}
VI xs;
int cur = lower_bound(all(layer), bridges[i].l) - layer.begin();
for (; cur != layer.size() && layer[cur] <= bridges[i].r; cur++) {
xs.pb(layer[cur]);
}
rep(j, xs.size()-1) {
int u = ind[{xs[j], bridges[i].y}];
int v = ind[{xs[j+1], bridges[i].y}];
int w = X[xs[j+1]] - X[xs[j]];
gp[u].pb({v, w});
gp[v].pb({u, w});
}
}
} else {
/* TEST 1, 2 */
addvertex(X[S], 0);
addvertex(X[T], 0);
for (auto&[a, b, c] : bridges) a = X[a], b = X[b];
sort(all(buildings), [](const BUILDING& a, const BUILDING& b){return a.h > b.h;});
sort(all(bridges), [](const BRIDGE& a, const BRIDGE& b){return a.y > b.y;});
/* horizontal */
set<int> st;
for (int j = 0, i = 0; i < bridges.size(); i++) {
auto&[l, r, y] = bridges[i];
while (j < buildings.size() && buildings[j].h >= y) st.insert(buildings[j++].x);
VI xs;
for (auto it = st.lower_bound(l); it != st.end() && *it <= r; it++) xs.pb(*it);
for (int x : xs) addvertex(x, y);
rep(i, xs.size()-1) {
int u = ind[{xs[i], y}];
int v = ind[{xs[i+1], y}];
int w = xs[i+1]-xs[i];
gp[u].pb({v, w});
gp[v].pb({u, w});
}
}
/* vertical */
VPI pts = point;
sort(all(pts));
rep(i, pts.size()-1) {
if (pts[i].ff != pts[i+1].ff) continue;
int u = ind[pts[i]];
int v = ind[pts[i+1]];
int w = pts[i+1].ss - pts[i].ss;
gp[u].pb({v, w});
gp[v].pb({u, w});
}
}
int n = gp.size();
priority_queue<PLL> pq;
VL dist(n, 1e18);
VI vis(n);
pq.push({0, 0});
dist[0] = 0;
while (pq.size()) {
int u = pq.top().ss;
pq.pop();
if (vis[u]) continue;
vis[u] = true;
for (auto[v, w] : gp[u]) {
if (dist[u] + w < dist[v]) {
dist[v] = dist[u] + w;
pq.push({-dist[v], v});
}
}
}
if (dist[1] == 1e18) return -1;
return dist[1];
}
Compilation message
walk.cpp: In function 'll min_distance(VI, VI, VI, VI, VI, int, int)':
walk.cpp:107:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
107 | if (S == 0 && T == X.size()-1) {
| ~~^~~~~~~~~~~~~
walk.cpp:116:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
116 | for (auto&[l, r, y] : bridges) {
| ^
walk.cpp:136:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<BRIDGE>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
136 | for (int i = 0; i < bridges.size(); i++) {
| ~~^~~~~~~~~~~~~~~~
walk.cpp:139:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
139 | while (j != pts.size() && pts[j].ss < bridges[i].y) j++;
| ~~^~~~~~~~~~~~~
walk.cpp:140:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
140 | while (j != pts.size() && pts[j].ss == bridges[i].y) layer.pb(pts[j++].ff);
| ~~^~~~~~~~~~~~~
walk.cpp:144:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
144 | for (; cur != layer.size() && layer[cur] <= bridges[i].r; cur++) {
| ~~~~^~~~~~~~~~~~~~~
walk.cpp:159:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
159 | for (auto&[a, b, c] : bridges) a = X[a], b = X[b];
| ^
walk.cpp:164:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<BRIDGE>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
164 | for (int j = 0, i = 0; i < bridges.size(); i++) {
| ~~^~~~~~~~~~~~~~~~
walk.cpp:165:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
165 | auto&[l, r, y] = bridges[i];
| ^
walk.cpp:166:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<BUILDING>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
166 | while (j < buildings.size() && buildings[j].h >= y) st.insert(buildings[j++].x);
| ~~^~~~~~~~~~~~~~~~~~
walk.cpp:202:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
202 | for (auto[v, w] : gp[u]) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
436 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
432 KB |
Output is correct |
3 |
Correct |
1198 ms |
118348 KB |
Output is correct |
4 |
Correct |
1046 ms |
127520 KB |
Output is correct |
5 |
Correct |
781 ms |
107792 KB |
Output is correct |
6 |
Correct |
618 ms |
94296 KB |
Output is correct |
7 |
Correct |
737 ms |
109352 KB |
Output is correct |
8 |
Correct |
1561 ms |
149348 KB |
Output is correct |
9 |
Correct |
887 ms |
108876 KB |
Output is correct |
10 |
Correct |
1682 ms |
170316 KB |
Output is correct |
11 |
Correct |
644 ms |
67156 KB |
Output is correct |
12 |
Correct |
315 ms |
39916 KB |
Output is correct |
13 |
Correct |
688 ms |
66636 KB |
Output is correct |
14 |
Correct |
225 ms |
41424 KB |
Output is correct |
15 |
Correct |
257 ms |
42972 KB |
Output is correct |
16 |
Correct |
263 ms |
44388 KB |
Output is correct |
17 |
Correct |
290 ms |
42340 KB |
Output is correct |
18 |
Correct |
292 ms |
45788 KB |
Output is correct |
19 |
Correct |
7 ms |
2200 KB |
Output is correct |
20 |
Correct |
96 ms |
21172 KB |
Output is correct |
21 |
Correct |
373 ms |
38600 KB |
Output is correct |
22 |
Correct |
338 ms |
39336 KB |
Output is correct |
23 |
Correct |
262 ms |
47976 KB |
Output is correct |
24 |
Correct |
322 ms |
40040 KB |
Output is correct |
25 |
Correct |
391 ms |
40552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
14156 KB |
Output is correct |
2 |
Correct |
698 ms |
68008 KB |
Output is correct |
3 |
Correct |
844 ms |
68304 KB |
Output is correct |
4 |
Correct |
905 ms |
73572 KB |
Output is correct |
5 |
Correct |
806 ms |
76624 KB |
Output is correct |
6 |
Correct |
749 ms |
70816 KB |
Output is correct |
7 |
Correct |
305 ms |
41064 KB |
Output is correct |
8 |
Correct |
376 ms |
39784 KB |
Output is correct |
9 |
Correct |
689 ms |
67792 KB |
Output is correct |
10 |
Correct |
280 ms |
41828 KB |
Output is correct |
11 |
Correct |
7 ms |
3416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
14156 KB |
Output is correct |
2 |
Correct |
698 ms |
68008 KB |
Output is correct |
3 |
Correct |
844 ms |
68304 KB |
Output is correct |
4 |
Correct |
905 ms |
73572 KB |
Output is correct |
5 |
Correct |
806 ms |
76624 KB |
Output is correct |
6 |
Correct |
749 ms |
70816 KB |
Output is correct |
7 |
Correct |
305 ms |
41064 KB |
Output is correct |
8 |
Correct |
376 ms |
39784 KB |
Output is correct |
9 |
Correct |
689 ms |
67792 KB |
Output is correct |
10 |
Correct |
280 ms |
41828 KB |
Output is correct |
11 |
Correct |
7 ms |
3416 KB |
Output is correct |
12 |
Correct |
777 ms |
69872 KB |
Output is correct |
13 |
Correct |
738 ms |
74136 KB |
Output is correct |
14 |
Correct |
824 ms |
75796 KB |
Output is correct |
15 |
Correct |
611 ms |
64264 KB |
Output is correct |
16 |
Correct |
667 ms |
66876 KB |
Output is correct |
17 |
Correct |
714 ms |
74636 KB |
Output is correct |
18 |
Correct |
614 ms |
63664 KB |
Output is correct |
19 |
Correct |
675 ms |
66136 KB |
Output is correct |
20 |
Correct |
348 ms |
40924 KB |
Output is correct |
21 |
Correct |
27 ms |
7124 KB |
Output is correct |
22 |
Correct |
525 ms |
61532 KB |
Output is correct |
23 |
Correct |
518 ms |
59416 KB |
Output is correct |
24 |
Correct |
334 ms |
44912 KB |
Output is correct |
25 |
Correct |
471 ms |
53592 KB |
Output is correct |
26 |
Correct |
234 ms |
37992 KB |
Output is correct |
27 |
Correct |
822 ms |
75684 KB |
Output is correct |
28 |
Correct |
779 ms |
73816 KB |
Output is correct |
29 |
Correct |
891 ms |
73280 KB |
Output is correct |
30 |
Correct |
355 ms |
41072 KB |
Output is correct |
31 |
Correct |
777 ms |
67884 KB |
Output is correct |
32 |
Correct |
343 ms |
40840 KB |
Output is correct |
33 |
Correct |
341 ms |
40272 KB |
Output is correct |
34 |
Correct |
283 ms |
44392 KB |
Output is correct |
35 |
Correct |
402 ms |
46596 KB |
Output is correct |
36 |
Correct |
403 ms |
42496 KB |
Output is correct |
37 |
Correct |
386 ms |
39688 KB |
Output is correct |
38 |
Correct |
347 ms |
39048 KB |
Output is correct |
39 |
Correct |
266 ms |
48076 KB |
Output is correct |
40 |
Correct |
375 ms |
40344 KB |
Output is correct |
41 |
Correct |
411 ms |
40064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
436 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
432 KB |
Output is correct |
20 |
Correct |
1198 ms |
118348 KB |
Output is correct |
21 |
Correct |
1046 ms |
127520 KB |
Output is correct |
22 |
Correct |
781 ms |
107792 KB |
Output is correct |
23 |
Correct |
618 ms |
94296 KB |
Output is correct |
24 |
Correct |
737 ms |
109352 KB |
Output is correct |
25 |
Correct |
1561 ms |
149348 KB |
Output is correct |
26 |
Correct |
887 ms |
108876 KB |
Output is correct |
27 |
Correct |
1682 ms |
170316 KB |
Output is correct |
28 |
Correct |
644 ms |
67156 KB |
Output is correct |
29 |
Correct |
315 ms |
39916 KB |
Output is correct |
30 |
Correct |
688 ms |
66636 KB |
Output is correct |
31 |
Correct |
225 ms |
41424 KB |
Output is correct |
32 |
Correct |
257 ms |
42972 KB |
Output is correct |
33 |
Correct |
263 ms |
44388 KB |
Output is correct |
34 |
Correct |
290 ms |
42340 KB |
Output is correct |
35 |
Correct |
292 ms |
45788 KB |
Output is correct |
36 |
Correct |
7 ms |
2200 KB |
Output is correct |
37 |
Correct |
96 ms |
21172 KB |
Output is correct |
38 |
Correct |
373 ms |
38600 KB |
Output is correct |
39 |
Correct |
338 ms |
39336 KB |
Output is correct |
40 |
Correct |
262 ms |
47976 KB |
Output is correct |
41 |
Correct |
322 ms |
40040 KB |
Output is correct |
42 |
Correct |
391 ms |
40552 KB |
Output is correct |
43 |
Correct |
133 ms |
14156 KB |
Output is correct |
44 |
Correct |
698 ms |
68008 KB |
Output is correct |
45 |
Correct |
844 ms |
68304 KB |
Output is correct |
46 |
Correct |
905 ms |
73572 KB |
Output is correct |
47 |
Correct |
806 ms |
76624 KB |
Output is correct |
48 |
Correct |
749 ms |
70816 KB |
Output is correct |
49 |
Correct |
305 ms |
41064 KB |
Output is correct |
50 |
Correct |
376 ms |
39784 KB |
Output is correct |
51 |
Correct |
689 ms |
67792 KB |
Output is correct |
52 |
Correct |
280 ms |
41828 KB |
Output is correct |
53 |
Correct |
7 ms |
3416 KB |
Output is correct |
54 |
Correct |
777 ms |
69872 KB |
Output is correct |
55 |
Correct |
738 ms |
74136 KB |
Output is correct |
56 |
Correct |
824 ms |
75796 KB |
Output is correct |
57 |
Correct |
611 ms |
64264 KB |
Output is correct |
58 |
Correct |
667 ms |
66876 KB |
Output is correct |
59 |
Correct |
714 ms |
74636 KB |
Output is correct |
60 |
Correct |
614 ms |
63664 KB |
Output is correct |
61 |
Correct |
675 ms |
66136 KB |
Output is correct |
62 |
Correct |
348 ms |
40924 KB |
Output is correct |
63 |
Correct |
27 ms |
7124 KB |
Output is correct |
64 |
Correct |
525 ms |
61532 KB |
Output is correct |
65 |
Correct |
518 ms |
59416 KB |
Output is correct |
66 |
Correct |
334 ms |
44912 KB |
Output is correct |
67 |
Correct |
471 ms |
53592 KB |
Output is correct |
68 |
Correct |
234 ms |
37992 KB |
Output is correct |
69 |
Correct |
822 ms |
75684 KB |
Output is correct |
70 |
Correct |
779 ms |
73816 KB |
Output is correct |
71 |
Correct |
891 ms |
73280 KB |
Output is correct |
72 |
Correct |
355 ms |
41072 KB |
Output is correct |
73 |
Correct |
777 ms |
67884 KB |
Output is correct |
74 |
Correct |
343 ms |
40840 KB |
Output is correct |
75 |
Correct |
341 ms |
40272 KB |
Output is correct |
76 |
Correct |
283 ms |
44392 KB |
Output is correct |
77 |
Correct |
402 ms |
46596 KB |
Output is correct |
78 |
Correct |
403 ms |
42496 KB |
Output is correct |
79 |
Correct |
386 ms |
39688 KB |
Output is correct |
80 |
Correct |
347 ms |
39048 KB |
Output is correct |
81 |
Correct |
266 ms |
48076 KB |
Output is correct |
82 |
Correct |
375 ms |
40344 KB |
Output is correct |
83 |
Correct |
411 ms |
40064 KB |
Output is correct |
84 |
Correct |
104 ms |
11928 KB |
Output is correct |
85 |
Execution timed out |
4037 ms |
510980 KB |
Time limit exceeded |
86 |
Halted |
0 ms |
0 KB |
- |