# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
415441 |
2021-06-01T05:58:58 Z |
wiwiho |
Sky Walking (IOI19_walk) |
C++14 |
|
4000 ms |
594608 KB |
#include "walk.h"
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define iter(a) a.begin(), a.end()
#define printv(a, b) { \
for(auto pv : a) b << pv << " "; \
b << "\n"; \
}
#define lsort(a) sort(iter(a))
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
const ll MAX = 1LL << 60;
int n, m;
vector<int> x, h, tl, tr, ty;
int sv, gv;
int ts = 1;
vector<vector<pll>> g;
vector<map<int, int>> vid;
int getid(int i, int t){
if(vid[i][t] == 0) vid[i][t] = ts++, g.eb();
return vid[i][t];
}
void addedge(int i1, int t1, int i2, int t2){
int u = getid(i1, t1);
int v = getid(i2, t2);
//cerr << "addedge " << i1 << " " << t1 << " " << i2 << " " << t2 << "\n";
g[u].eb(mp(v, abs(x[i1] - x[i2]) + abs(t1 - t2)));
g[v].eb(mp(u, abs(x[i1] - x[i2]) + abs(t1 - t2)));
}
vector<vector<pii>> st;
void build(int l, int r, int id){
if(l == r){
st[id].eb(mp(h[l], l));
return;
}
int m = (l + r) / 2;
build(l, m, id * 2 + 1);
build(m + 1, r, id * 2 + 2);
st[id].resize(r - l + 1);
merge(iter(st[id * 2 + 1]), iter(st[id * 2 + 2]), st[id].begin(), greater<>());
}
vector<int> inter;
void bridge(int l, int r, int y, int L, int R, int id){
if(l == L && r == R){
for(pii i : st[id]){
if(i.F < y) break;
inter.eb(i.S);
}
return;
}
int M = (L + R) / 2;
if(r <= M) bridge(l, r, y, L, M, id * 2 + 1);
else if(l > M) bridge(l, r, y, M + 1, R, id * 2 + 2);
else{
bridge(l, M, y, L, M, id * 2 + 1);
bridge(M + 1, r, y, M + 1, R, id * 2 + 2);
}
}
ll min_distance(vector<int> _x, vector<int> _h, vector<int> _l, vector<int> _r, vector<int> _y, int _s, int _g){
x = _x; h = _h; tl = _l; tr = _r; ty = _y; sv = _s; gv = _g;
n = x.size();
m = ty.size();
g.resize(1);
vid.resize(n);
st.resize(4 * n);
build(0, n - 1, 0);
for(int i = 0; i < m; i++){
inter.clear();
bridge(tl[i], tr[i], ty[i], 0, n - 1, 0);
lsort(inter);
//cerr << "test " << i << " ";
//printv(inter, cerr);
int lst = -1;
for(int j : inter){
if(lst != -1) addedge(lst, ty[i], j, ty[i]);
lst = j;
}
}
getid(sv, 0);
getid(gv, 0);
for(int i = 0; i < n; i++){
for(auto it = vid[i].begin(); it != vid[i].end() && next(it) != vid[i].end(); it++){
addedge(i, it->F, i, next(it)->F);
}
}
priority_queue<pll, vector<pll>, greater<>> pq;
vector<ll> dis(ts, MAX);
dis[getid(sv, 0)] = 0;
pq.push(mp(0, getid(sv, 0)));
while(!pq.empty()){
int now = pq.top().S;
ll d = pq.top().F;
pq.pop();
if(d != dis[now]) continue;
for(pll i : g[now]){
if(d + i.S >= dis[i.F]) continue;
dis[i.F] = d + i.S;
pq.push(mp(d + i.S, i.F));
}
}
if(dis[getid(gv, 0)] == MAX) return -1;
return dis[getid(gv, 0)];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
288 KB |
Output is correct |
9 |
Correct |
1 ms |
280 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
2 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
2 ms |
204 KB |
Output is correct |
17 |
Correct |
3 ms |
420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1658 ms |
145760 KB |
Output is correct |
4 |
Correct |
1105 ms |
175896 KB |
Output is correct |
5 |
Correct |
644 ms |
155768 KB |
Output is correct |
6 |
Correct |
550 ms |
138684 KB |
Output is correct |
7 |
Correct |
730 ms |
155732 KB |
Output is correct |
8 |
Correct |
1755 ms |
188772 KB |
Output is correct |
9 |
Correct |
739 ms |
148836 KB |
Output is correct |
10 |
Correct |
1260 ms |
238656 KB |
Output is correct |
11 |
Correct |
715 ms |
84064 KB |
Output is correct |
12 |
Correct |
318 ms |
68328 KB |
Output is correct |
13 |
Correct |
1057 ms |
210644 KB |
Output is correct |
14 |
Correct |
445 ms |
67304 KB |
Output is correct |
15 |
Correct |
489 ms |
67672 KB |
Output is correct |
16 |
Correct |
446 ms |
66960 KB |
Output is correct |
17 |
Correct |
425 ms |
64648 KB |
Output is correct |
18 |
Correct |
580 ms |
81428 KB |
Output is correct |
19 |
Correct |
10 ms |
3336 KB |
Output is correct |
20 |
Correct |
110 ms |
32576 KB |
Output is correct |
21 |
Correct |
306 ms |
60188 KB |
Output is correct |
22 |
Correct |
413 ms |
67560 KB |
Output is correct |
23 |
Correct |
478 ms |
79820 KB |
Output is correct |
24 |
Correct |
388 ms |
66304 KB |
Output is correct |
25 |
Correct |
443 ms |
63992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
162 ms |
16248 KB |
Output is correct |
2 |
Execution timed out |
4054 ms |
594608 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
162 ms |
16248 KB |
Output is correct |
2 |
Execution timed out |
4054 ms |
594608 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
288 KB |
Output is correct |
9 |
Correct |
1 ms |
280 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
2 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
2 ms |
204 KB |
Output is correct |
17 |
Correct |
3 ms |
420 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1658 ms |
145760 KB |
Output is correct |
21 |
Correct |
1105 ms |
175896 KB |
Output is correct |
22 |
Correct |
644 ms |
155768 KB |
Output is correct |
23 |
Correct |
550 ms |
138684 KB |
Output is correct |
24 |
Correct |
730 ms |
155732 KB |
Output is correct |
25 |
Correct |
1755 ms |
188772 KB |
Output is correct |
26 |
Correct |
739 ms |
148836 KB |
Output is correct |
27 |
Correct |
1260 ms |
238656 KB |
Output is correct |
28 |
Correct |
715 ms |
84064 KB |
Output is correct |
29 |
Correct |
318 ms |
68328 KB |
Output is correct |
30 |
Correct |
1057 ms |
210644 KB |
Output is correct |
31 |
Correct |
445 ms |
67304 KB |
Output is correct |
32 |
Correct |
489 ms |
67672 KB |
Output is correct |
33 |
Correct |
446 ms |
66960 KB |
Output is correct |
34 |
Correct |
425 ms |
64648 KB |
Output is correct |
35 |
Correct |
580 ms |
81428 KB |
Output is correct |
36 |
Correct |
10 ms |
3336 KB |
Output is correct |
37 |
Correct |
110 ms |
32576 KB |
Output is correct |
38 |
Correct |
306 ms |
60188 KB |
Output is correct |
39 |
Correct |
413 ms |
67560 KB |
Output is correct |
40 |
Correct |
478 ms |
79820 KB |
Output is correct |
41 |
Correct |
388 ms |
66304 KB |
Output is correct |
42 |
Correct |
443 ms |
63992 KB |
Output is correct |
43 |
Correct |
162 ms |
16248 KB |
Output is correct |
44 |
Execution timed out |
4054 ms |
594608 KB |
Time limit exceeded |
45 |
Halted |
0 ms |
0 KB |
- |