#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define f first
#define s second
#define int long long
#define size(x) (int)((x).size())
const int inf = 1e18;
int min_distance(std::vector<signed> pos, std::vector<signed> heightOf, std::vector<signed> leftP, std::vector<signed> rightP, std::vector<signed> yLevel, signed s, signed g) {
const int n = size(pos);
const int nbP = size(leftP);
vector<int> finishAt [n];
for (int i = 0; i < nbP; i++) {
finishAt[rightP[i]].push_back(yLevel[i]);
}
finishAt[0].push_back(0);
map<int, int> dp [n];
for (int i : finishAt[n-1]) {
dp[n-1][i] = i;
}
vector<pair<int, int>> addAt [n];
vector<pair<int, int>> removeAt [n];
for (int i = 0; i < nbP; i++) {
addAt[rightP[i]].push_back({yLevel[i], rightP[i]});
removeAt[leftP[i]].push_back({yLevel[i], rightP[i]});
}
map<int, int> m;
for (int i = n-1; i >= 0; i--) {
if (i < n-1) {
for (int j : finishAt[i]) {
dp[i][j] = inf;
auto it = m.upper_bound(j);
if (!m.empty() && it != m.end()) {
int loc = dp[it->second][it->first]+it->first-j;
dp[i][j] = min(dp[i][j], loc);
}
if (!m.empty() && it != m.begin()) {
it = prev(it);
int loc = dp[it->second][it->first]+j-it->first;
dp[i][j] = min(dp[i][j], loc);
}
}
}
for (auto j : removeAt[i]) {
assert(m.count(j.f));
m.erase(j.f);
}
for (auto j : addAt[i]) {
assert(!m.count(j.f));
m[j.f] = j.s;
}
}
int res = dp[0][0];
res += (int)(pos[n-1]-pos[0]);
if (res >= inf) res = -1;
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
9164 KB |
Output is correct |
2 |
Correct |
151 ms |
14416 KB |
Output is correct |
3 |
Correct |
172 ms |
16548 KB |
Output is correct |
4 |
Correct |
215 ms |
29952 KB |
Output is correct |
5 |
Correct |
274 ms |
35356 KB |
Output is correct |
6 |
Correct |
256 ms |
31096 KB |
Output is correct |
7 |
Correct |
95 ms |
22476 KB |
Output is correct |
8 |
Correct |
116 ms |
31684 KB |
Output is correct |
9 |
Correct |
267 ms |
32860 KB |
Output is correct |
10 |
Correct |
166 ms |
32328 KB |
Output is correct |
11 |
Correct |
13 ms |
7116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
9164 KB |
Output is correct |
2 |
Correct |
151 ms |
14416 KB |
Output is correct |
3 |
Correct |
172 ms |
16548 KB |
Output is correct |
4 |
Correct |
215 ms |
29952 KB |
Output is correct |
5 |
Correct |
274 ms |
35356 KB |
Output is correct |
6 |
Correct |
256 ms |
31096 KB |
Output is correct |
7 |
Correct |
95 ms |
22476 KB |
Output is correct |
8 |
Correct |
116 ms |
31684 KB |
Output is correct |
9 |
Correct |
267 ms |
32860 KB |
Output is correct |
10 |
Correct |
166 ms |
32328 KB |
Output is correct |
11 |
Correct |
13 ms |
7116 KB |
Output is correct |
12 |
Correct |
154 ms |
18356 KB |
Output is correct |
13 |
Correct |
198 ms |
33740 KB |
Output is correct |
14 |
Correct |
288 ms |
39072 KB |
Output is correct |
15 |
Correct |
160 ms |
33100 KB |
Output is correct |
16 |
Correct |
162 ms |
33316 KB |
Output is correct |
17 |
Correct |
182 ms |
33248 KB |
Output is correct |
18 |
Correct |
187 ms |
33088 KB |
Output is correct |
19 |
Correct |
207 ms |
33340 KB |
Output is correct |
20 |
Correct |
103 ms |
25072 KB |
Output is correct |
21 |
Correct |
34 ms |
15660 KB |
Output is correct |
22 |
Correct |
138 ms |
30084 KB |
Output is correct |
23 |
Correct |
142 ms |
31156 KB |
Output is correct |
24 |
Correct |
130 ms |
32804 KB |
Output is correct |
25 |
Correct |
125 ms |
30368 KB |
Output is correct |
26 |
Correct |
144 ms |
35028 KB |
Output is correct |
27 |
Correct |
290 ms |
37344 KB |
Output is correct |
28 |
Correct |
176 ms |
33600 KB |
Output is correct |
29 |
Correct |
300 ms |
34856 KB |
Output is correct |
30 |
Correct |
98 ms |
25248 KB |
Output is correct |
31 |
Correct |
241 ms |
36800 KB |
Output is correct |
32 |
Correct |
150 ms |
31556 KB |
Output is correct |
33 |
Correct |
136 ms |
34996 KB |
Output is correct |
34 |
Correct |
168 ms |
33952 KB |
Output is correct |
35 |
Correct |
179 ms |
32704 KB |
Output is correct |
36 |
Correct |
143 ms |
32108 KB |
Output is correct |
37 |
Correct |
129 ms |
29380 KB |
Output is correct |
38 |
Correct |
130 ms |
34676 KB |
Output is correct |
39 |
Correct |
158 ms |
32432 KB |
Output is correct |
40 |
Correct |
122 ms |
32928 KB |
Output is correct |
41 |
Correct |
120 ms |
30980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |