// I can do all things through Christ who strenghthens me
// Philippians 4:13
#include "bits/stdc++.h"
#include "walk.h"
using namespace std;
#define REP(i, j, k) for (int i = j; i < (k); i++)
#define RREP(i, j, k) for (int i = j; i >= (k); i--)
template <class T>
inline bool mnto(T &a, const T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T &a, const T b) {return a < b ? a = b, 1 : 0;}
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int) x.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> lll;
typedef vector<iii> viii;
#ifndef DEBUG
#define cerr if (0) cerr
#endif
const int INF = 1000000005;
const ll LINF = 1000000000000000005;
const int MAXN = 100005;
int n, m;
vi vy[MAXN];
map<int, int> mp[MAXN];
vll d[MAXN];
priority_queue<lll, vector<lll>, greater<lll>> pq;
ll min_distance(vi x, vi h, vi l, vi r, vi y, int s, int g) {
n = SZ(x), m = SZ(l);
REP (i, 0, m) {
REP (p, l[i], r[i] + 1) {
if (h[p] < y[i]) {
continue;
}
mp[p][y[i]] = SZ(vy[p]);
vy[p].pb(i);
}
}
REP (i, 0, n) {
d[i] = vll(SZ(vy[i]), LINF);
sort(ALL(vy[i]), [&] (int l, int r) {
return y[l] < y[r];
});
}
REP (j, 0, SZ(vy[s])) {
d[s][j] = y[vy[s][j]];
pq.push({d[s][j], s, j});
}
while (!pq.empty()) {
auto [ud, up, ui] = pq.top(); pq.pop();
if (ud != d[up][ui]) {
continue;
}
int id = vy[up][ui];
cerr << up << ' ' << y[id] << ": " << ud << '\n';
REP (j, max(0, (int) ui - 1), min(SZ(vy[up]), (int) ui + 2)) {
if (mnto(d[up][j], ud + abs(y[id] - y[vy[up][j]]))) {
pq.push({d[up][j], up, j});
}
}
REP (p, l[id], r[id] + 1) {
if (h[p] < y[id]) {
continue;
}
//int j = mp[p][y[id]];
REP (j, 0, SZ(vy[p])) {
if (y[vy[p][j]] != y[id]) {
continue;
}
if (mnto(d[p][j], ud + abs(x[p] - x[up]))) {
pq.push({d[p][j], p, j});
}
}
}
}
ll ans = LINF;
REP (j, 0, SZ(vy[g])) {
mnto(ans, d[g][j] + y[vy[g][j]]);
}
if (ans == LINF) {
return -1;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9668 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
4 ms |
9696 KB |
Output is correct |
4 |
Correct |
4 ms |
9684 KB |
Output is correct |
5 |
Correct |
5 ms |
9740 KB |
Output is correct |
6 |
Correct |
5 ms |
9684 KB |
Output is correct |
7 |
Correct |
5 ms |
9684 KB |
Output is correct |
8 |
Correct |
5 ms |
9684 KB |
Output is correct |
9 |
Correct |
5 ms |
9684 KB |
Output is correct |
10 |
Correct |
5 ms |
9772 KB |
Output is correct |
11 |
Correct |
4 ms |
9684 KB |
Output is correct |
12 |
Correct |
4 ms |
9684 KB |
Output is correct |
13 |
Correct |
4 ms |
9632 KB |
Output is correct |
14 |
Correct |
6 ms |
9596 KB |
Output is correct |
15 |
Correct |
5 ms |
9684 KB |
Output is correct |
16 |
Correct |
4 ms |
9684 KB |
Output is correct |
17 |
Correct |
5 ms |
9684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
4 ms |
9684 KB |
Output is correct |
3 |
Correct |
1040 ms |
55808 KB |
Output is correct |
4 |
Correct |
425 ms |
60432 KB |
Output is correct |
5 |
Correct |
207 ms |
52204 KB |
Output is correct |
6 |
Correct |
848 ms |
47244 KB |
Output is correct |
7 |
Correct |
216 ms |
52332 KB |
Output is correct |
8 |
Correct |
1848 ms |
67604 KB |
Output is correct |
9 |
Correct |
257 ms |
52356 KB |
Output is correct |
10 |
Correct |
695 ms |
78200 KB |
Output is correct |
11 |
Correct |
248 ms |
35472 KB |
Output is correct |
12 |
Correct |
113 ms |
29172 KB |
Output is correct |
13 |
Correct |
547 ms |
71564 KB |
Output is correct |
14 |
Correct |
3450 ms |
28452 KB |
Output is correct |
15 |
Execution timed out |
4059 ms |
29200 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
15800 KB |
Output is correct |
2 |
Execution timed out |
4101 ms |
317296 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
15800 KB |
Output is correct |
2 |
Execution timed out |
4101 ms |
317296 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9668 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
4 ms |
9696 KB |
Output is correct |
4 |
Correct |
4 ms |
9684 KB |
Output is correct |
5 |
Correct |
5 ms |
9740 KB |
Output is correct |
6 |
Correct |
5 ms |
9684 KB |
Output is correct |
7 |
Correct |
5 ms |
9684 KB |
Output is correct |
8 |
Correct |
5 ms |
9684 KB |
Output is correct |
9 |
Correct |
5 ms |
9684 KB |
Output is correct |
10 |
Correct |
5 ms |
9772 KB |
Output is correct |
11 |
Correct |
4 ms |
9684 KB |
Output is correct |
12 |
Correct |
4 ms |
9684 KB |
Output is correct |
13 |
Correct |
4 ms |
9632 KB |
Output is correct |
14 |
Correct |
6 ms |
9596 KB |
Output is correct |
15 |
Correct |
5 ms |
9684 KB |
Output is correct |
16 |
Correct |
4 ms |
9684 KB |
Output is correct |
17 |
Correct |
5 ms |
9684 KB |
Output is correct |
18 |
Correct |
5 ms |
9684 KB |
Output is correct |
19 |
Correct |
4 ms |
9684 KB |
Output is correct |
20 |
Correct |
1040 ms |
55808 KB |
Output is correct |
21 |
Correct |
425 ms |
60432 KB |
Output is correct |
22 |
Correct |
207 ms |
52204 KB |
Output is correct |
23 |
Correct |
848 ms |
47244 KB |
Output is correct |
24 |
Correct |
216 ms |
52332 KB |
Output is correct |
25 |
Correct |
1848 ms |
67604 KB |
Output is correct |
26 |
Correct |
257 ms |
52356 KB |
Output is correct |
27 |
Correct |
695 ms |
78200 KB |
Output is correct |
28 |
Correct |
248 ms |
35472 KB |
Output is correct |
29 |
Correct |
113 ms |
29172 KB |
Output is correct |
30 |
Correct |
547 ms |
71564 KB |
Output is correct |
31 |
Correct |
3450 ms |
28452 KB |
Output is correct |
32 |
Execution timed out |
4059 ms |
29200 KB |
Time limit exceeded |
33 |
Halted |
0 ms |
0 KB |
- |