#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
#define sp " "
#define endl "\n"
#define pb push_back
#define pii pair<ll, ll>
#define st first
#define nd second
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define LL node * 2
#define RR node * 2 + 1
#define ll long long
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 s, int g) {
ll n = x.size(), m = l.size();
vector<map<ll, long long>> dist(n);
vector<vector<pii>> adj(n);
vector<vector<ll>> points(n);
vector<array<ll, 3>> events;
vector<ll> last(m, -1);
set<pii> open;
for (ll i = 0; i < m; i++)
events.pb({l[i], i, -1}), events.pb({r[i] + 1, i, 1});
sort(events.begin(), events.end());
ll it = 0;
for (ll i = 0; i < n; i++){
while(it < events.size() && events[it][0] == i){
ll t = events[it][2], ind = events[it][1];
if (t == -1) open.insert({-y[ind], ind});
else open.erase({-y[ind], ind});
it++;
}
auto it2 = open.lower_bound({-h[i], 0});
while(it2 != open.end()){
points[i].pb(-it2->st);
ll ind = it2->nd;
if (last[ind] != -1){
adj[i].pb({y[ind], last[ind]});
adj[last[ind]].pb({y[ind], i});
}
last[ind] = i;
it2++;
}
points[i].pb(0);
}
for (ll i = 0; i < n; i++){
sort(points[i].begin(), points[i].end());
sort(adj[i].begin(), adj[i].end());
}
priority_queue<array<long long, 3>> q;
q.push({0, s, 0});
dist[s][0] = 0;
while(!q.empty()){
array<ll, 3> tmp = q.top();
q.pop();
long long X = tmp[1], y = tmp[2], d = -tmp[0];
if (dist[X][y] < d) continue;
//cout<<X<<sp<<y<<sp<<d<<endl;
ll pos = lower_bound(points[X].begin(), points[X].end(), y) - points[X].begin();
if (pos > 0){
ll to = points[X][pos - 1];
ll tmp = d + abs(to - y);
if (dist[X].count(to) == 0 || dist[X][to] > tmp){
dist[X][to] = tmp;
q.push({-tmp, X, to});
}
}
if (pos < points[X].size()){
ll to = points[X][pos + 1];
ll tmp = d + abs(to - y);
if (dist[X].count(to) == 0 || dist[X][to] > tmp){
dist[X][to] = tmp;
q.push({-tmp, X, to});
}
}
pos = lower_bound(adj[X].begin(), adj[X].end(), make_pair(y, (ll)0)) - adj[X].begin();
while(pos < adj[X].size() && adj[X][pos].st == y){
ll to = adj[X][pos].nd;
ll tmp = d + (ll)abs(x[X] - x[to]);
if (dist[to].count(y) == 0 || dist[to][y] > tmp){
dist[to][y] = tmp;
q.push({-tmp, to, y});
}
pos++;
}
}
if (dist[g].count(0)) return dist[g][0];
return -1;
}
/*
int main() {
fileio();
int n, m;
assert(2 == scanf("%d%d", &n, &m));
vector<int> x(n), h(n);
for (int i = 0; i < n; i++)
assert(2 == scanf("%d%d", &x[i], &h[i]));
vector<int> l(m), r(m), y(m);
for (int i = 0; i < m; i++)
assert(3 == scanf("%d%d%d", &l[i], &r[i], &y[i]));
int s, g;
assert(2 == scanf("%d%d", &s, &g));
fclose(stdin);
long long result = min_distance(x, h, l, r, y, s, g);
printf("%lld\n", result);
fclose(stdout);
return 0;
}*/
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:34:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | while(it < events.size() && events[it][0] == i){
| ~~~^~~~~~~~~~~~~~~
walk.cpp:78:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | if (pos < points[X].size()){
| ~~~~^~~~~~~~~~~~~~~~~~
walk.cpp:88:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | while(pos < adj[X].size() && adj[X][pos].st == y){
| ~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
553 ms |
94912 KB |
Output is correct |
4 |
Correct |
336 ms |
109936 KB |
Output is correct |
5 |
Correct |
102 ms |
54508 KB |
Output is correct |
6 |
Correct |
103 ms |
51124 KB |
Output is correct |
7 |
Correct |
102 ms |
54420 KB |
Output is correct |
8 |
Correct |
844 ms |
115748 KB |
Output is correct |
9 |
Correct |
151 ms |
60348 KB |
Output is correct |
10 |
Correct |
529 ms |
149440 KB |
Output is correct |
11 |
Correct |
199 ms |
56888 KB |
Output is correct |
12 |
Correct |
99 ms |
51244 KB |
Output is correct |
13 |
Correct |
386 ms |
137072 KB |
Output is correct |
14 |
Correct |
77 ms |
32448 KB |
Output is correct |
15 |
Correct |
111 ms |
52032 KB |
Output is correct |
16 |
Incorrect |
110 ms |
50952 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
14276 KB |
Output is correct |
2 |
Execution timed out |
4046 ms |
357584 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
14276 KB |
Output is correct |
2 |
Execution timed out |
4046 ms |
357584 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
553 ms |
94912 KB |
Output is correct |
21 |
Correct |
336 ms |
109936 KB |
Output is correct |
22 |
Correct |
102 ms |
54508 KB |
Output is correct |
23 |
Correct |
103 ms |
51124 KB |
Output is correct |
24 |
Correct |
102 ms |
54420 KB |
Output is correct |
25 |
Correct |
844 ms |
115748 KB |
Output is correct |
26 |
Correct |
151 ms |
60348 KB |
Output is correct |
27 |
Correct |
529 ms |
149440 KB |
Output is correct |
28 |
Correct |
199 ms |
56888 KB |
Output is correct |
29 |
Correct |
99 ms |
51244 KB |
Output is correct |
30 |
Correct |
386 ms |
137072 KB |
Output is correct |
31 |
Correct |
77 ms |
32448 KB |
Output is correct |
32 |
Correct |
111 ms |
52032 KB |
Output is correct |
33 |
Incorrect |
110 ms |
50952 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |