#include <bits/stdc++.h>
#include "walk.h"
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
const int N = 1e5 + 7, C = 12e5 + 7;
const ll inf = 1e18;
int n, m, cnt;
ll g[N], h[N], dis[C];
vector <int> ad[N];
vector <pii> adj[C];
void Edge(int x, int y, int val) {
adj[x].pb({y, val});
adj[y].pb({x, val});
}
ll min_distance(vi x, vi h, vi l, vi r, vi y, int sta, int en) {
n = x.size(); m = l.size();
map <int, vector <int> > ma;
map <pii, int> wh;
for (int i = 0; i < n; i++) ma[h[i]].pb(i);
for (int i = 0; i < m; i++) ma[y[i]].pb(i+n);
set <int> st;
cnt = n;
while (!ma.empty()) {
auto it = *(--ma.end());
for (auto xx : it.S) {
if (xx < n) st.insert(xx);
else {
xx -= n;
auto p = st.lower_bound(l[xx]);
int la = -1;
while (p != st.end() && *p <= r[xx]) {
ad[*p].pb(it.F);
if (wh.find({*p, it.F}) == wh.end()) wh[{*p, it.F}] = cnt++;
if (la != -1) Edge(wh[{la, it.F}], wh[{*p, it.F}], x[*p]-x[la]);
la = *p;
++p;
}
}
}
ma.erase(--ma.end());
}
for (int i = 0; i < n; i++) {
sort(all(ad[i]));
if (ad[i].empty()) continue;
Edge(i, wh[{i, ad[i][0]}], ad[i][0]);
for (int j = 1; j < ad[i].size(); j++) Edge(wh[{i, ad[i][j-1]}], wh[{i, ad[i][j]}], ad[i][j]-ad[i][j-1]);
}
set <pii> s;
s.insert({0, sta});
for (int i = 0; i < cnt; i++) dis[i] = inf;
dis[sta] = 0;
while (!s.empty()) {
auto p = s.begin();
int xx = p -> S;
s.erase(p);
for (auto y : adj[xx]) {
if (dis[xx] + y.S < dis[y.F]) {
if (dis[y.F] != inf) s.erase({dis[y.F], y.F});
dis[y.F] = dis[xx] + y.S;
s.insert({dis[y.F], y.F});
}
}
}
return (dis[en] >= inf) ? -1 : dis[en];
}
Compilation message
walk.cpp: In function 'll min_distance(vi, vi, vi, vi, vi, int, int)':
walk.cpp:61:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for (int j = 1; j < ad[i].size(); j++) Edge(wh[{i, ad[i][j-1]}], wh[{i, ad[i][j]}], ad[i][j]-ad[i][j-1]);
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
31320 KB |
Output is correct |
2 |
Correct |
4 ms |
31324 KB |
Output is correct |
3 |
Correct |
4 ms |
31388 KB |
Output is correct |
4 |
Correct |
4 ms |
31324 KB |
Output is correct |
5 |
Correct |
5 ms |
31324 KB |
Output is correct |
6 |
Correct |
5 ms |
31320 KB |
Output is correct |
7 |
Correct |
4 ms |
31324 KB |
Output is correct |
8 |
Correct |
4 ms |
31324 KB |
Output is correct |
9 |
Correct |
4 ms |
31324 KB |
Output is correct |
10 |
Correct |
5 ms |
31324 KB |
Output is correct |
11 |
Correct |
4 ms |
31380 KB |
Output is correct |
12 |
Correct |
4 ms |
31324 KB |
Output is correct |
13 |
Correct |
4 ms |
31324 KB |
Output is correct |
14 |
Correct |
4 ms |
31324 KB |
Output is correct |
15 |
Correct |
4 ms |
31324 KB |
Output is correct |
16 |
Correct |
5 ms |
31360 KB |
Output is correct |
17 |
Correct |
5 ms |
31324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
31324 KB |
Output is correct |
2 |
Correct |
4 ms |
31324 KB |
Output is correct |
3 |
Correct |
1010 ms |
143700 KB |
Output is correct |
4 |
Execution timed out |
4059 ms |
150100 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
45832 KB |
Output is correct |
2 |
Runtime error |
1340 ms |
459092 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
45832 KB |
Output is correct |
2 |
Runtime error |
1340 ms |
459092 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
31320 KB |
Output is correct |
2 |
Correct |
4 ms |
31324 KB |
Output is correct |
3 |
Correct |
4 ms |
31388 KB |
Output is correct |
4 |
Correct |
4 ms |
31324 KB |
Output is correct |
5 |
Correct |
5 ms |
31324 KB |
Output is correct |
6 |
Correct |
5 ms |
31320 KB |
Output is correct |
7 |
Correct |
4 ms |
31324 KB |
Output is correct |
8 |
Correct |
4 ms |
31324 KB |
Output is correct |
9 |
Correct |
4 ms |
31324 KB |
Output is correct |
10 |
Correct |
5 ms |
31324 KB |
Output is correct |
11 |
Correct |
4 ms |
31380 KB |
Output is correct |
12 |
Correct |
4 ms |
31324 KB |
Output is correct |
13 |
Correct |
4 ms |
31324 KB |
Output is correct |
14 |
Correct |
4 ms |
31324 KB |
Output is correct |
15 |
Correct |
4 ms |
31324 KB |
Output is correct |
16 |
Correct |
5 ms |
31360 KB |
Output is correct |
17 |
Correct |
5 ms |
31324 KB |
Output is correct |
18 |
Correct |
5 ms |
31324 KB |
Output is correct |
19 |
Correct |
4 ms |
31324 KB |
Output is correct |
20 |
Correct |
1010 ms |
143700 KB |
Output is correct |
21 |
Execution timed out |
4059 ms |
150100 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |