#include <bits/stdc++.h>
using namespace std;
#define forn(j, i, n) for(int i = j; i <= n; ++i)
#define FOR(j, i, n) for(int i = j; i < n; ++i)
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(), v.end()
#define nfor(j, i, n) for(int i = n; i >= j; --i)
#define ll long long
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//const int maxn=2e5+10;
#define o cout <<"BUG\n";
#define pii pair <int, int>
using namespace std;
const int maxn = 1e5+10;
ll n, m, x[maxn], y[maxn], h[maxn], l[maxn], r[maxn];
vector <ll> dot[maxn], ver[maxn];
long long min_distance(vector<int> X, vector<int> H,
vector<int> L2, vector<int> R2, vector<int> Y2, int s, int g)
{
m = L2.size();
s++, g++;
forn(1, i, m)
{
l[i] = L2[i-1]+1;
r[i] = R2[i-1]+1;
y[i] = Y2[i-1];
}
n = X.size();
forn(1, i, n)
{
x[i] = X[i-1];
h[i] = H[i-1];
}
forn(1, i, m)
{
forn(l[i], j, r[i])
{
if(h[j] >= y[i])
dot[j].pb(y[i]);
}
}
int cnt = 0;
forn(1, i, n)
{
dot[i].pb(0);
sort(all(dot[i]));
dot[i].erase(unique(all(dot[i])), dot[i].end());
ver[i].assign(dot[i].size(), 0);
FOR(0, j, dot[i].size()) ver[i][j] = ++cnt;
}
vector <vector <pair <ll, ll> > > edge;
edge.assign(cnt+10, {});
forn(1, i, n)
{
FOR(1, j, dot[i].size())
{
edge[ver[i][j]].pb({ver[i][j-1], dot[i][j]-dot[i][j-1]});
edge[ver[i][j-1]].pb({ver[i][j], dot[i][j]-dot[i][j-1]});
}
}
forn(1, i, m)
{
int last = -1;
int indx = 0;
forn(l[i], j, r[i])
{
if(h[j] < y[i]) continue;
int se = lower_bound(all(dot[j]), y[i]) - dot[j].begin();
int nw = ver[j][se];
if(last != -1)
{
edge[last].pb({nw, x[j]-x[indx]});
edge[nw].pb({last, x[j]-x[indx]});
}
indx = j;
last = nw;
}
}
/* forn(1, i, n)
{
cout << " FOR " << i << endl;
FOR(0, j, dot[i].size()) cout << dot[i][j] << " " << ver[i][j] << endl;
cout << endl;
}*/
// forn(1, i, cnt)
// for(auto j : edge[i]) cout << i << " " << j.f << " " << j.s << endl;
ll inf = 1e18;
vector <ll> dist(cnt+12);
forn(1, i, cnt)
{
dist[i] = inf;
}
int v = ver[s][0];
dist[v] = 0;
set <pair <ll, int> > st;
st.insert({0, v});
while(st.size())
{
int v = st.begin()->s;
st.erase(st.begin());
for(auto to : edge[v])
{
if(dist[to.f] > dist[v] + to.s)
{
st.erase({dist[to.f], to.f});
dist[to.f] = dist[v]+to.s;
st.insert({dist[to.f], to.f});
}
}
}
if(dist[ver[g][0]] == inf) return -1;
return dist[ver[g][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:6:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
6 | #define FOR(j, i, n) for(int i = j; i < n; ++i)
......
57 | FOR(0, j, dot[i].size()) ver[i][j] = ++cnt;
| ~~~~~~~~~~~~~~~~
walk.cpp:57:3: note: in expansion of macro 'FOR'
57 | FOR(0, j, dot[i].size()) ver[i][j] = ++cnt;
| ^~~
walk.cpp:6:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
6 | #define FOR(j, i, n) for(int i = j; i < n; ++i)
......
63 | FOR(1, j, dot[i].size())
| ~~~~~~~~~~~~~~~~
walk.cpp:63:3: note: in expansion of macro 'FOR'
63 | FOR(1, j, dot[i].size())
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
5004 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
2 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5008 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
4 ms |
5076 KB |
Output is correct |
13 |
Correct |
4 ms |
4948 KB |
Output is correct |
14 |
Correct |
2 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5000 KB |
Output is correct |
3 |
Correct |
837 ms |
111968 KB |
Output is correct |
4 |
Correct |
667 ms |
124624 KB |
Output is correct |
5 |
Correct |
431 ms |
108696 KB |
Output is correct |
6 |
Correct |
1257 ms |
97388 KB |
Output is correct |
7 |
Correct |
408 ms |
108872 KB |
Output is correct |
8 |
Correct |
1118 ms |
139468 KB |
Output is correct |
9 |
Correct |
469 ms |
107288 KB |
Output is correct |
10 |
Correct |
1027 ms |
166692 KB |
Output is correct |
11 |
Correct |
350 ms |
66252 KB |
Output is correct |
12 |
Correct |
185 ms |
52772 KB |
Output is correct |
13 |
Correct |
830 ms |
148248 KB |
Output is correct |
14 |
Execution timed out |
4059 ms |
47552 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
18116 KB |
Output is correct |
2 |
Execution timed out |
4093 ms |
677056 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
18116 KB |
Output is correct |
2 |
Execution timed out |
4093 ms |
677056 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
5004 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
2 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5008 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
4 ms |
5076 KB |
Output is correct |
13 |
Correct |
4 ms |
4948 KB |
Output is correct |
14 |
Correct |
2 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
5076 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
5000 KB |
Output is correct |
20 |
Correct |
837 ms |
111968 KB |
Output is correct |
21 |
Correct |
667 ms |
124624 KB |
Output is correct |
22 |
Correct |
431 ms |
108696 KB |
Output is correct |
23 |
Correct |
1257 ms |
97388 KB |
Output is correct |
24 |
Correct |
408 ms |
108872 KB |
Output is correct |
25 |
Correct |
1118 ms |
139468 KB |
Output is correct |
26 |
Correct |
469 ms |
107288 KB |
Output is correct |
27 |
Correct |
1027 ms |
166692 KB |
Output is correct |
28 |
Correct |
350 ms |
66252 KB |
Output is correct |
29 |
Correct |
185 ms |
52772 KB |
Output is correct |
30 |
Correct |
830 ms |
148248 KB |
Output is correct |
31 |
Execution timed out |
4059 ms |
47552 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |