#include <bits/stdc++.h>
#include "walk.h"
using namespace std;
//macros
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define INF 1e18
#define pb push_back
#define fi first
#define se second
#define sz size()
ll min_distance(vi x, vi h, vi l, vi r, vi y, int s, int g) {
int n, m;
n = x.sz; m = l.sz;
priority_queue<iii> pq;
map<int,ll> mp;
RE(i,m) pq.push({r[i],2,i});
RE(i,m) pq.push({l[i],1,i});
RE(i,m) pq.push({r[i],0,i});
vll dp(m);
ll ans = INF;
while(!pq.empty()) {
iii p = pq.top(); pq.pop();
int x, t, i;
tie(x, t, i) = p;
if(t == 2) {
if(x == n-1) {
dp[i] = y[i];
} else {
dp[i] = INF;
auto it = mp.lower_bound(y[i]);
if(it != mp.end())
dp[i] = min(dp[i], it->se + it->fi - y[i]);
it = mp.upper_bound(y[i]);
if(it != mp.begin())
--it, dp[i] = min(dp[i], it->se + y[i] - it->fi);
}
} else if(t == 1) {
if(x == 0)
ans = min(ans, dp[i]+y[i]);
mp.erase(y[i]);
} else {
mp[y[i]] = dp[i];
}
}
if(ans == INF) ans = -1;
else ans += x[n-1]-x[0];
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
5492 KB |
Output is correct |
2 |
Correct |
195 ms |
10728 KB |
Output is correct |
3 |
Correct |
208 ms |
11244 KB |
Output is correct |
4 |
Correct |
232 ms |
14568 KB |
Output is correct |
5 |
Correct |
304 ms |
18908 KB |
Output is correct |
6 |
Correct |
281 ms |
15452 KB |
Output is correct |
7 |
Correct |
108 ms |
9324 KB |
Output is correct |
8 |
Correct |
176 ms |
14572 KB |
Output is correct |
9 |
Correct |
252 ms |
15708 KB |
Output is correct |
10 |
Correct |
176 ms |
15068 KB |
Output is correct |
11 |
Correct |
14 ms |
1920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
5492 KB |
Output is correct |
2 |
Correct |
195 ms |
10728 KB |
Output is correct |
3 |
Correct |
208 ms |
11244 KB |
Output is correct |
4 |
Correct |
232 ms |
14568 KB |
Output is correct |
5 |
Correct |
304 ms |
18908 KB |
Output is correct |
6 |
Correct |
281 ms |
15452 KB |
Output is correct |
7 |
Correct |
108 ms |
9324 KB |
Output is correct |
8 |
Correct |
176 ms |
14572 KB |
Output is correct |
9 |
Correct |
252 ms |
15708 KB |
Output is correct |
10 |
Correct |
176 ms |
15068 KB |
Output is correct |
11 |
Correct |
14 ms |
1920 KB |
Output is correct |
12 |
Correct |
213 ms |
11244 KB |
Output is correct |
13 |
Correct |
244 ms |
14568 KB |
Output is correct |
14 |
Correct |
309 ms |
19036 KB |
Output is correct |
15 |
Correct |
204 ms |
14440 KB |
Output is correct |
16 |
Correct |
208 ms |
14696 KB |
Output is correct |
17 |
Correct |
206 ms |
14568 KB |
Output is correct |
18 |
Correct |
205 ms |
14440 KB |
Output is correct |
19 |
Correct |
207 ms |
14568 KB |
Output is correct |
20 |
Correct |
126 ms |
9196 KB |
Output is correct |
21 |
Correct |
36 ms |
3960 KB |
Output is correct |
22 |
Correct |
169 ms |
11368 KB |
Output is correct |
23 |
Correct |
181 ms |
14056 KB |
Output is correct |
24 |
Correct |
172 ms |
14056 KB |
Output is correct |
25 |
Correct |
162 ms |
11368 KB |
Output is correct |
26 |
Correct |
187 ms |
14684 KB |
Output is correct |
27 |
Correct |
325 ms |
17920 KB |
Output is correct |
28 |
Correct |
206 ms |
14696 KB |
Output is correct |
29 |
Correct |
270 ms |
15320 KB |
Output is correct |
30 |
Correct |
115 ms |
9324 KB |
Output is correct |
31 |
Correct |
280 ms |
15712 KB |
Output is correct |
32 |
Correct |
161 ms |
13416 KB |
Output is correct |
33 |
Correct |
164 ms |
13800 KB |
Output is correct |
34 |
Correct |
174 ms |
13672 KB |
Output is correct |
35 |
Correct |
173 ms |
13672 KB |
Output is correct |
36 |
Correct |
191 ms |
13432 KB |
Output is correct |
37 |
Correct |
150 ms |
12908 KB |
Output is correct |
38 |
Correct |
152 ms |
13672 KB |
Output is correct |
39 |
Correct |
170 ms |
14556 KB |
Output is correct |
40 |
Correct |
156 ms |
13416 KB |
Output is correct |
41 |
Correct |
149 ms |
12904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |