# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1021238 |
2024-07-12T16:12:49 Z |
c2zi6 |
Sky Walking (IOI19_walk) |
C++14 |
|
4000 ms |
509852 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;
};
struct BUILDINGCOMPORATOR {
bool operator()(const BUILDING& a, const BUILDING& b) const {
return mkp(a.x, a.h) < mkp(b.x, b.h);
}
};
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]};
sort(all(buildings), [](const BUILDING& a, const BUILDING& b){return a.h > b.h;});
vector<BRIDGE> bridges(L.size());
rep(i, L.size()) bridges[i] = {X[L[i]], X[R[i]], Y[i]};
sort(all(bridges), [](const BRIDGE& a, const BRIDGE& b){return a.y > b.y;});
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());
};
addvertex(X[S], 0);
addvertex(X[T], 0);
{/* horizontal edges */
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 edges */
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:66:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<BRIDGE>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (int j = 0, i = 0; i < bridges.size(); i++) {
| ~~^~~~~~~~~~~~~~~~
walk.cpp:67:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
67 | auto&[l, r, y] = bridges[i];
| ^
walk.cpp:68:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<BUILDING>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | while (j < buildings.size() && buildings[j].h >= y) st.insert(buildings[j++].x);
| ~~^~~~~~~~~~~~~~~~~~
walk.cpp:104:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
104 | 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 |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 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 |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1105 ms |
116012 KB |
Output is correct |
4 |
Correct |
1062 ms |
117468 KB |
Output is correct |
5 |
Correct |
751 ms |
100116 KB |
Output is correct |
6 |
Correct |
632 ms |
88024 KB |
Output is correct |
7 |
Correct |
712 ms |
100396 KB |
Output is correct |
8 |
Correct |
1474 ms |
146988 KB |
Output is correct |
9 |
Correct |
819 ms |
102956 KB |
Output is correct |
10 |
Correct |
1508 ms |
165680 KB |
Output is correct |
11 |
Correct |
556 ms |
62744 KB |
Output is correct |
12 |
Correct |
336 ms |
42344 KB |
Output is correct |
13 |
Correct |
1279 ms |
144636 KB |
Output is correct |
14 |
Correct |
219 ms |
40296 KB |
Output is correct |
15 |
Correct |
255 ms |
41572 KB |
Output is correct |
16 |
Correct |
239 ms |
41316 KB |
Output is correct |
17 |
Correct |
290 ms |
39780 KB |
Output is correct |
18 |
Correct |
196 ms |
44384 KB |
Output is correct |
19 |
Correct |
6 ms |
2200 KB |
Output is correct |
20 |
Correct |
90 ms |
20464 KB |
Output is correct |
21 |
Correct |
316 ms |
38504 KB |
Output is correct |
22 |
Correct |
261 ms |
39224 KB |
Output is correct |
23 |
Correct |
225 ms |
48996 KB |
Output is correct |
24 |
Correct |
257 ms |
39012 KB |
Output is correct |
25 |
Correct |
297 ms |
40028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
79 ms |
12928 KB |
Output is correct |
2 |
Execution timed out |
4091 ms |
509852 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
79 ms |
12928 KB |
Output is correct |
2 |
Execution timed out |
4091 ms |
509852 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 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 |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1105 ms |
116012 KB |
Output is correct |
21 |
Correct |
1062 ms |
117468 KB |
Output is correct |
22 |
Correct |
751 ms |
100116 KB |
Output is correct |
23 |
Correct |
632 ms |
88024 KB |
Output is correct |
24 |
Correct |
712 ms |
100396 KB |
Output is correct |
25 |
Correct |
1474 ms |
146988 KB |
Output is correct |
26 |
Correct |
819 ms |
102956 KB |
Output is correct |
27 |
Correct |
1508 ms |
165680 KB |
Output is correct |
28 |
Correct |
556 ms |
62744 KB |
Output is correct |
29 |
Correct |
336 ms |
42344 KB |
Output is correct |
30 |
Correct |
1279 ms |
144636 KB |
Output is correct |
31 |
Correct |
219 ms |
40296 KB |
Output is correct |
32 |
Correct |
255 ms |
41572 KB |
Output is correct |
33 |
Correct |
239 ms |
41316 KB |
Output is correct |
34 |
Correct |
290 ms |
39780 KB |
Output is correct |
35 |
Correct |
196 ms |
44384 KB |
Output is correct |
36 |
Correct |
6 ms |
2200 KB |
Output is correct |
37 |
Correct |
90 ms |
20464 KB |
Output is correct |
38 |
Correct |
316 ms |
38504 KB |
Output is correct |
39 |
Correct |
261 ms |
39224 KB |
Output is correct |
40 |
Correct |
225 ms |
48996 KB |
Output is correct |
41 |
Correct |
257 ms |
39012 KB |
Output is correct |
42 |
Correct |
297 ms |
40028 KB |
Output is correct |
43 |
Correct |
79 ms |
12928 KB |
Output is correct |
44 |
Execution timed out |
4091 ms |
509852 KB |
Time limit exceeded |
45 |
Halted |
0 ms |
0 KB |
- |