#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
ll min_distance(vector<int> X, vector<int> H, vector<int> L, vector<int> R, vector<int> Y, int start, int goal) {
int n = (int)X.size(), m = (int)L.size();
vector<vector<pair<int, int>>> todo(n+1);
for(int i = 0; i < m; i++){
todo[L[i]].emplace_back(Y[i], 1);
todo[R[i]+1].emplace_back(Y[i], -1);
}
todo[1].emplace_back(0, -1);
map<int, ll> mp;
mp[0] = 0;
set<int> just_added;
for(int i = 0; i < n; i++){
for(auto [y, op] : todo[i]){
if(op == -1 && !just_added.count(y)) mp.erase(y);
}
just_added.clear();
for(auto [y, op] : todo[i]){
if(op == 1){
auto it = mp.lower_bound(y);
ll v = INF;
if(it != mp.end() && it->first <= H[i]) v = min(v, it->second+it->first-y);
if(it != mp.begin()){
it--;
v = min(v, it->second+y-it->first);
}
if(v == INF) continue;
mp[y] = v;
just_added.insert(y);
}
}
}
if(mp.empty() || mp.begin()->first > H[n-1]) return -1;
return mp.begin()->first+mp.begin()->second+X[n-1]-X[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
3348 KB |
Output is correct |
2 |
Correct |
105 ms |
5040 KB |
Output is correct |
3 |
Correct |
114 ms |
5860 KB |
Output is correct |
4 |
Correct |
121 ms |
10392 KB |
Output is correct |
5 |
Correct |
151 ms |
16060 KB |
Output is correct |
6 |
Correct |
139 ms |
12744 KB |
Output is correct |
7 |
Correct |
60 ms |
7612 KB |
Output is correct |
8 |
Correct |
73 ms |
9684 KB |
Output is correct |
9 |
Correct |
142 ms |
13224 KB |
Output is correct |
10 |
Correct |
102 ms |
13100 KB |
Output is correct |
11 |
Correct |
10 ms |
2260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
3348 KB |
Output is correct |
2 |
Correct |
105 ms |
5040 KB |
Output is correct |
3 |
Correct |
114 ms |
5860 KB |
Output is correct |
4 |
Correct |
121 ms |
10392 KB |
Output is correct |
5 |
Correct |
151 ms |
16060 KB |
Output is correct |
6 |
Correct |
139 ms |
12744 KB |
Output is correct |
7 |
Correct |
60 ms |
7612 KB |
Output is correct |
8 |
Correct |
73 ms |
9684 KB |
Output is correct |
9 |
Correct |
142 ms |
13224 KB |
Output is correct |
10 |
Correct |
102 ms |
13100 KB |
Output is correct |
11 |
Correct |
10 ms |
2260 KB |
Output is correct |
12 |
Correct |
93 ms |
5784 KB |
Output is correct |
13 |
Correct |
73 ms |
10052 KB |
Output is correct |
14 |
Correct |
162 ms |
20152 KB |
Output is correct |
15 |
Correct |
111 ms |
14852 KB |
Output is correct |
16 |
Correct |
105 ms |
15036 KB |
Output is correct |
17 |
Correct |
107 ms |
15156 KB |
Output is correct |
18 |
Correct |
105 ms |
14752 KB |
Output is correct |
19 |
Correct |
106 ms |
15008 KB |
Output is correct |
20 |
Correct |
74 ms |
10776 KB |
Output is correct |
21 |
Correct |
24 ms |
6184 KB |
Output is correct |
22 |
Correct |
70 ms |
12680 KB |
Output is correct |
23 |
Correct |
64 ms |
13072 KB |
Output is correct |
24 |
Correct |
79 ms |
13136 KB |
Output is correct |
25 |
Correct |
61 ms |
12844 KB |
Output is correct |
26 |
Correct |
63 ms |
13128 KB |
Output is correct |
27 |
Correct |
161 ms |
19132 KB |
Output is correct |
28 |
Correct |
78 ms |
13984 KB |
Output is correct |
29 |
Correct |
154 ms |
16704 KB |
Output is correct |
30 |
Incorrect |
66 ms |
10668 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |