#include <bits/stdc++.h>
#include "walk.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const ll INFLL = 1e18;
long long min_distance(std::vector<int> x, std::vector<int> h, std::vector<int> L, std::vector<int> R, std::vector<int> y, int start, int end) {
int n = x.size(),
m = y.size();
vector<pii> cc;
vector<vector<int>> skywalk(n);
cc.push_back({start, 0});
cc.push_back({end, 0});
skywalk[start].push_back(0);
skywalk[end].push_back(0);
for(int i = 0 ; i < m ; i++)
{
for(int j = L[i] ; j <= R[i] ; j++)
{
if(h[j] >= y[i])
{
cc.push_back({j, y[i]});
skywalk[j].push_back(y[i]);
}
}
}
sort(cc.begin(), cc.end());
cc.resize(unique(cc.begin(), cc.end()) - cc.begin());
vector<vector<pair<int, ll>>> g(cc.size());
for(int i = 0 ; i < n ; i++)
{
sort(skywalk[i].begin(), skywalk[i].end());
for(int j = 0 ; j + 1 < skywalk[i].size() ; j++)
{
int a = lower_bound(cc.begin(), cc.end(), (pii){i, skywalk[i][j]}) - cc.begin(),
b = lower_bound(cc.begin(), cc.end(), (pii){i, skywalk[i][j+1]}) - cc.begin();
ll w = skywalk[i][j+1] - skywalk[i][j];
g[a].push_back({b, w});
g[b].push_back({a, w});
}
}
for(int i = 0 ; i < m ; i++)
{
int a = -1;
for(int j = L[i] ; j <= R[i] ; j++)
{
if(h[j] >= y[i])
{
if(a == -1)
{
a = lower_bound(cc.begin(), cc.end(), (pii){j, y[i]}) - cc.begin();
}
else
{
int b = lower_bound(cc.begin(), cc.end(), (pii){j, y[i]}) - cc.begin();
ll w = x[cc[b].first] - x[cc[a].first];
g[a].push_back({b, w});
g[b].push_back({a, w});
a = b;
}
}
}
}
priority_queue<pair<ll, int>> q;
int s = lower_bound(cc.begin(), cc.end(), (pii){start, 0}) - cc.begin();
q.push({0, s});
vector<bool> flag(cc.size());
vector<ll> dp(cc.size(), INFLL);
dp[s] = 0;
while(q.size())
{
int nod = q.top().second;
q.pop();
if(flag[nod])
continue;
flag[nod] = true;
for(auto i: g[nod])
{
if(dp[i.first] > dp[nod] + i.second)
{
dp[i.first] = dp[nod] + i.second;
q.push({-dp[i.first], i.first});
}
}
}
int e = lower_bound(cc.begin(), cc.end(), (pii){end, 0}) - cc.begin();
return (dp[e] == INFLL ? -1 : dp[e]);
}
Compilation message
walk.cpp: In function 'long long int min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:43:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int j = 0 ; j + 1 < skywalk[i].size() ; j++)
| ~~~~~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
3 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1203 ms |
99704 KB |
Output is correct |
4 |
Correct |
1030 ms |
103328 KB |
Output is correct |
5 |
Correct |
813 ms |
88516 KB |
Output is correct |
6 |
Correct |
2115 ms |
78080 KB |
Output is correct |
7 |
Correct |
740 ms |
88664 KB |
Output is correct |
8 |
Correct |
1564 ms |
126556 KB |
Output is correct |
9 |
Correct |
822 ms |
88792 KB |
Output is correct |
10 |
Correct |
1548 ms |
144352 KB |
Output is correct |
11 |
Correct |
548 ms |
52936 KB |
Output is correct |
12 |
Correct |
271 ms |
31896 KB |
Output is correct |
13 |
Correct |
1234 ms |
126588 KB |
Output is correct |
14 |
Execution timed out |
4043 ms |
24964 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
109 ms |
14820 KB |
Output is correct |
2 |
Execution timed out |
4086 ms |
527088 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
109 ms |
14820 KB |
Output is correct |
2 |
Execution timed out |
4086 ms |
527088 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
3 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1203 ms |
99704 KB |
Output is correct |
21 |
Correct |
1030 ms |
103328 KB |
Output is correct |
22 |
Correct |
813 ms |
88516 KB |
Output is correct |
23 |
Correct |
2115 ms |
78080 KB |
Output is correct |
24 |
Correct |
740 ms |
88664 KB |
Output is correct |
25 |
Correct |
1564 ms |
126556 KB |
Output is correct |
26 |
Correct |
822 ms |
88792 KB |
Output is correct |
27 |
Correct |
1548 ms |
144352 KB |
Output is correct |
28 |
Correct |
548 ms |
52936 KB |
Output is correct |
29 |
Correct |
271 ms |
31896 KB |
Output is correct |
30 |
Correct |
1234 ms |
126588 KB |
Output is correct |
31 |
Execution timed out |
4043 ms |
24964 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |