#include "walk.h"
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <iostream>
using namespace std;
long long min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r, vector<int> y, int s, int e) {
int n = x.size();
int m = l.size();
vector<int> g[n], v[n];
vector<long long> dp(m);
long long ans = (1LL << 60);
set<pair<int, int>> is;
for (int i = 0; i < m; ++i) {
g[l[i]].push_back(i);
v[r[i]].push_back(i);
}
for (int i = 0; i < n; ++i) {
for (auto it : g[i]) {
auto jt = is.lower_bound({y[i], -(1 << 30)});
dp[it] = (1LL << 60);
if (jt != is.end())
dp[it] = dp[jt->second] + abs(jt->first - y[it]);
if (jt != is.begin()) {
jt = prev(jt);
dp[it] = min(dp[it], dp[jt->second] + abs(jt->first - y[it]));
}
is.insert({y[it], it});
}
if (i == n - 1)
for (auto it : is)
ans = min(ans, dp[it.second]);
for (auto it : v[i])
is.insert({y[it], it});
}
return ans + x[n - 1] - x[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
58 ms |
5648 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
58 ms |
5648 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |