# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1070714 |
2024-08-22T17:08:57 Z |
Gray |
Sky Walking (IOI19_walk) |
C++17 |
|
3488 ms |
1048576 KB |
#include "walk.h"
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ln "\n"
#define ll long long
#define ld long double
const ll inf=2e18;
struct Graph{
vector<vector<pair<ll, ll>>> A;
vector<pair<ll, ll>> id;
ll sz, ind;
Graph(){
sz=0; ind=0;
}
ll add_node(ll x, ll y){
A.push_back(vector<pair<ll, ll>>());
id.push_back({x, y});
ind++; sz++;
return ind-1;
}
void add_edge(ll u, ll v, ll w){
A[u].push_back({v, w});
A[v].push_back({u, w});
}
ll shortest(ll s, ll g){
vector<ll> dist(sz, -1);
set<pair<ll, ll>> que;
que.insert({0, s});
while (!que.empty()){
auto cur = *que.begin();
que.erase(que.begin());
if (dist[cur.ss]!=-1) continue;
dist[cur.ss]=cur.ff;
for (auto v:A[cur.ss]){
if (dist[v.ff]==-1) que.insert({cur.ff+v.ss, v.ff});
}
}
return dist[g];
}
void debug(){
for (ll i=0; i<sz; i++){
cout << id[i].ff << "," << id[i].ss << ": ";
for (auto v:A[i]){
cout << id[v.ff].ff << "," << id[v.ff].ss << "-" << v.ss << " ";
}
cout << ln;
}
}
};
long long min_distance(std::vector<int> x, std::vector<int> h, std::vector<int> l, std::vector<int> r, std::vector<int> y, int s, int g) {
ll n = x.size(), m=l.size();
set<pair<ll, pair<ll, ll>>> bd;
Graph gr;
for (ll i=0; i<n; i++){
ll cn = gr.add_node(x[i], 0);
if (i==s) s=cn;
if (i==g) g=cn;
bd.insert({i, {cn, 0}});
}
map<ll, pair<vector<ll>, vector<ll>>> ev;
for (ll i=0; i<n; i++){
ev[h[i]].ss.push_back(i);
}
for (ll i=0; i<m; i++){
ev[y[i]].ff.push_back(i);
}
for (auto &[height, data]:ev){
for (auto bi:data.ff){
auto cur = bd.lower_bound({l[bi], {-1, -1}});
ll prev=-1, prevx=-1;
// cout << l[bi] << " " << r[bi] << " -> " << (*cur).ff << endl;
// continue;
while ((*cur).ff<=r[bi] and (*cur).ff>=l[bi]){
// cout << &cur << endl;
ll ti = (*cur).ff;
if ((*cur).ss.ss<y[bi]){
ll nw = gr.add_node(x[ti], y[bi]);
gr.add_edge(nw, (*cur).ss.ff, y[bi]-(*cur).ss.ss);
bd.erase(cur);
bd.insert({ti, {nw, y[bi]}});
cur = bd.find({ti, {nw, y[bi]}});
}
if (prev!=-1){
gr.add_edge(prev, (*cur).ss.ff, x[ti]-prevx);
}
prevx=x[ti]; prev=(*cur).ss.ff;
if ((*cur)==*bd.rbegin()) break;
cur++;
}
}
for (auto hsi:data.ss){
bd.erase(bd.lower_bound({hsi, {-1, -1}}));
}
}
// gr.debug();
return gr.shortest(s, g);
}
# |
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 |
0 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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 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 |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
432 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 |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
651 ms |
108868 KB |
Output is correct |
4 |
Correct |
784 ms |
134204 KB |
Output is correct |
5 |
Correct |
500 ms |
113472 KB |
Output is correct |
6 |
Correct |
414 ms |
103740 KB |
Output is correct |
7 |
Correct |
470 ms |
116136 KB |
Output is correct |
8 |
Correct |
748 ms |
134072 KB |
Output is correct |
9 |
Correct |
528 ms |
114236 KB |
Output is correct |
10 |
Correct |
895 ms |
179264 KB |
Output is correct |
11 |
Correct |
406 ms |
73092 KB |
Output is correct |
12 |
Correct |
424 ms |
69212 KB |
Output is correct |
13 |
Correct |
832 ms |
153664 KB |
Output is correct |
14 |
Correct |
242 ms |
59484 KB |
Output is correct |
15 |
Correct |
200 ms |
45408 KB |
Output is correct |
16 |
Correct |
232 ms |
45248 KB |
Output is correct |
17 |
Correct |
225 ms |
43728 KB |
Output is correct |
18 |
Correct |
170 ms |
56728 KB |
Output is correct |
19 |
Correct |
7 ms |
2836 KB |
Output is correct |
20 |
Correct |
68 ms |
28472 KB |
Output is correct |
21 |
Correct |
188 ms |
44124 KB |
Output is correct |
22 |
Correct |
226 ms |
45284 KB |
Output is correct |
23 |
Correct |
221 ms |
58196 KB |
Output is correct |
24 |
Correct |
205 ms |
45344 KB |
Output is correct |
25 |
Correct |
214 ms |
43612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
12664 KB |
Output is correct |
2 |
Correct |
3488 ms |
659968 KB |
Output is correct |
3 |
Runtime error |
2155 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
12664 KB |
Output is correct |
2 |
Correct |
3488 ms |
659968 KB |
Output is correct |
3 |
Runtime error |
2155 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
0 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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 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 |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
432 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 |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
651 ms |
108868 KB |
Output is correct |
21 |
Correct |
784 ms |
134204 KB |
Output is correct |
22 |
Correct |
500 ms |
113472 KB |
Output is correct |
23 |
Correct |
414 ms |
103740 KB |
Output is correct |
24 |
Correct |
470 ms |
116136 KB |
Output is correct |
25 |
Correct |
748 ms |
134072 KB |
Output is correct |
26 |
Correct |
528 ms |
114236 KB |
Output is correct |
27 |
Correct |
895 ms |
179264 KB |
Output is correct |
28 |
Correct |
406 ms |
73092 KB |
Output is correct |
29 |
Correct |
424 ms |
69212 KB |
Output is correct |
30 |
Correct |
832 ms |
153664 KB |
Output is correct |
31 |
Correct |
242 ms |
59484 KB |
Output is correct |
32 |
Correct |
200 ms |
45408 KB |
Output is correct |
33 |
Correct |
232 ms |
45248 KB |
Output is correct |
34 |
Correct |
225 ms |
43728 KB |
Output is correct |
35 |
Correct |
170 ms |
56728 KB |
Output is correct |
36 |
Correct |
7 ms |
2836 KB |
Output is correct |
37 |
Correct |
68 ms |
28472 KB |
Output is correct |
38 |
Correct |
188 ms |
44124 KB |
Output is correct |
39 |
Correct |
226 ms |
45284 KB |
Output is correct |
40 |
Correct |
221 ms |
58196 KB |
Output is correct |
41 |
Correct |
205 ms |
45344 KB |
Output is correct |
42 |
Correct |
214 ms |
43612 KB |
Output is correct |
43 |
Correct |
54 ms |
12664 KB |
Output is correct |
44 |
Correct |
3488 ms |
659968 KB |
Output is correct |
45 |
Runtime error |
2155 ms |
1048576 KB |
Execution killed with signal 9 |
46 |
Halted |
0 ms |
0 KB |
- |