#include "walk.h"
#include <queue>
#include <algorithm>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<ll, int>;
#define sz(x) (int)x.size()
#define fi first
#define se second
const int MAXN = 3e6;
const ll INF = 1e18;
int n;
vi G[MAXN]; vll W[MAXN];
void create_link(int u, int v, ll w) {
G[u].push_back(v);
G[v].push_back(u);
W[u].push_back(w);
W[v].push_back(w);
}
ll dijkstra(int s, int g) {
vll dist(n, INF);
priority_queue<ii> q;
dist[s] = 0;
q.push( {-0, s} );
while(!q.empty()) {
ii p = q.top(); q.pop();
int u = p.se;
if(dist[u] != -p.fi) continue;
for(int i=0; i<sz(G[p.se]); i++) {
int v = G[p.se][i];
ll w = W[p.se][i];
if(-p.fi + w < dist[v]) {
dist[v] = -p.fi + w;
q.push( { -dist[v], v } );
}
}
}
if(dist[g] == INF) return -1;
return dist[g];
}
ll min_distance(vi x, vi h, vi l, vi r, vi y, int s, int g) {
n = sz(x);
vector<pair<int, int>> bridge, re;
for(int i=0; i<sz(l); i++) bridge.push_back( { y[i], i } );
sort(bridge.begin(), bridge.end());
for(int i=0; i<n; i++) re.push_back( { 0, i } );
for(pair<int,int> p : bridge) {
int index = p.se;
create_link(re[l[index]].se, n, p.fi - re[l[index]].fi);
re[l[index]] = { p.fi, n };
pair<int,int> current_node = { x[l[index]], n };
n++;
for(int i = l[index]+1; i <= r[index]; i++) {
if(p.fi <= h[i]) {
create_link(current_node.se, n, x[i] - current_node.fi);
current_node = { x[i], n };
n++;
create_link(current_node.se, re[i].se, p.fi - re[i].fi);
re[i] = { p.fi, current_node.se };
}
}
}
return dijkstra(s, g);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
141056 KB |
Output is correct |
2 |
Correct |
75 ms |
141144 KB |
Output is correct |
3 |
Correct |
81 ms |
141088 KB |
Output is correct |
4 |
Correct |
77 ms |
141084 KB |
Output is correct |
5 |
Correct |
76 ms |
141124 KB |
Output is correct |
6 |
Correct |
75 ms |
141140 KB |
Output is correct |
7 |
Correct |
81 ms |
141124 KB |
Output is correct |
8 |
Correct |
88 ms |
141124 KB |
Output is correct |
9 |
Correct |
74 ms |
141088 KB |
Output is correct |
10 |
Correct |
77 ms |
141220 KB |
Output is correct |
11 |
Correct |
74 ms |
141124 KB |
Output is correct |
12 |
Correct |
75 ms |
141124 KB |
Output is correct |
13 |
Correct |
75 ms |
141132 KB |
Output is correct |
14 |
Correct |
75 ms |
141112 KB |
Output is correct |
15 |
Correct |
76 ms |
141056 KB |
Output is correct |
16 |
Correct |
75 ms |
141120 KB |
Output is correct |
17 |
Correct |
76 ms |
141200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
141124 KB |
Output is correct |
2 |
Correct |
85 ms |
141100 KB |
Output is correct |
3 |
Correct |
639 ms |
207728 KB |
Output is correct |
4 |
Correct |
746 ms |
217364 KB |
Output is correct |
5 |
Correct |
493 ms |
207388 KB |
Output is correct |
6 |
Correct |
872 ms |
200688 KB |
Output is correct |
7 |
Correct |
492 ms |
207540 KB |
Output is correct |
8 |
Correct |
796 ms |
224912 KB |
Output is correct |
9 |
Correct |
586 ms |
206548 KB |
Output is correct |
10 |
Correct |
995 ms |
243508 KB |
Output is correct |
11 |
Correct |
470 ms |
180648 KB |
Output is correct |
12 |
Correct |
347 ms |
173372 KB |
Output is correct |
13 |
Correct |
834 ms |
231740 KB |
Output is correct |
14 |
Correct |
2298 ms |
171832 KB |
Output is correct |
15 |
Correct |
1422 ms |
172568 KB |
Output is correct |
16 |
Correct |
361 ms |
172644 KB |
Output is correct |
17 |
Correct |
353 ms |
171484 KB |
Output is correct |
18 |
Execution timed out |
4080 ms |
156560 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
167 ms |
153548 KB |
Output is correct |
2 |
Runtime error |
1495 ms |
769180 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
167 ms |
153548 KB |
Output is correct |
2 |
Runtime error |
1495 ms |
769180 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
141056 KB |
Output is correct |
2 |
Correct |
75 ms |
141144 KB |
Output is correct |
3 |
Correct |
81 ms |
141088 KB |
Output is correct |
4 |
Correct |
77 ms |
141084 KB |
Output is correct |
5 |
Correct |
76 ms |
141124 KB |
Output is correct |
6 |
Correct |
75 ms |
141140 KB |
Output is correct |
7 |
Correct |
81 ms |
141124 KB |
Output is correct |
8 |
Correct |
88 ms |
141124 KB |
Output is correct |
9 |
Correct |
74 ms |
141088 KB |
Output is correct |
10 |
Correct |
77 ms |
141220 KB |
Output is correct |
11 |
Correct |
74 ms |
141124 KB |
Output is correct |
12 |
Correct |
75 ms |
141124 KB |
Output is correct |
13 |
Correct |
75 ms |
141132 KB |
Output is correct |
14 |
Correct |
75 ms |
141112 KB |
Output is correct |
15 |
Correct |
76 ms |
141056 KB |
Output is correct |
16 |
Correct |
75 ms |
141120 KB |
Output is correct |
17 |
Correct |
76 ms |
141200 KB |
Output is correct |
18 |
Correct |
78 ms |
141124 KB |
Output is correct |
19 |
Correct |
85 ms |
141100 KB |
Output is correct |
20 |
Correct |
639 ms |
207728 KB |
Output is correct |
21 |
Correct |
746 ms |
217364 KB |
Output is correct |
22 |
Correct |
493 ms |
207388 KB |
Output is correct |
23 |
Correct |
872 ms |
200688 KB |
Output is correct |
24 |
Correct |
492 ms |
207540 KB |
Output is correct |
25 |
Correct |
796 ms |
224912 KB |
Output is correct |
26 |
Correct |
586 ms |
206548 KB |
Output is correct |
27 |
Correct |
995 ms |
243508 KB |
Output is correct |
28 |
Correct |
470 ms |
180648 KB |
Output is correct |
29 |
Correct |
347 ms |
173372 KB |
Output is correct |
30 |
Correct |
834 ms |
231740 KB |
Output is correct |
31 |
Correct |
2298 ms |
171832 KB |
Output is correct |
32 |
Correct |
1422 ms |
172568 KB |
Output is correct |
33 |
Correct |
361 ms |
172644 KB |
Output is correct |
34 |
Correct |
353 ms |
171484 KB |
Output is correct |
35 |
Execution timed out |
4080 ms |
156560 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |