#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
const ll N = 5005;
typedef vector <int> vi;
bool vis[N][N];
vector <pair <int, int> > adj[N][N];
int min_distance(vi x, vi h, vi l, vi r, vi y, int s, int g) {
int n, m, i, j;
n = x.size(); m = l.size();
for(i = 0; i < n; i++) {
for(j = h[i]; j >= 1; j--) {
adj[x[i]][j].pb(mp(x[i], j - 1));
adj[x[i]][j - 1].pb(mp(x[i], j));
}
}
for(i = 0; i < m; i++) {
for(j = x[l[i]] + 1; j <= x[r[i]]; j++) {
adj[j][y[i]].pb(mp(j - 1, y[i]));
adj[j - 1][y[i]].pb(mp(j, y[i]));
}
}
queue <pair <pair <int, int>, int> > q;
q.push(mp(mp(x[s], 0), 0));
while(!q.empty()) {
auto v = q.front();
q.pop();
if(v.F.F == x[g] && !v.F.S) return v.S;
if(vis[v.F.F][v.F.S]) continue;
vis[v.F.F][v.F.S] = true;
for(auto &to: adj[v.F.F][v.F.S]) {
if(vis[to.F][to.S]) continue;
q.push(mp(mp(to.F, to.S), v.S + 1));
}
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
343 ms |
588664 KB |
Output is correct |
2 |
Correct |
335 ms |
588680 KB |
Output is correct |
3 |
Runtime error |
992 ms |
1048576 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
359 ms |
588664 KB |
Output is correct |
2 |
Correct |
334 ms |
588664 KB |
Output is correct |
3 |
Runtime error |
875 ms |
1048576 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
841 ms |
1048576 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
841 ms |
1048576 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
343 ms |
588664 KB |
Output is correct |
2 |
Correct |
335 ms |
588680 KB |
Output is correct |
3 |
Runtime error |
992 ms |
1048576 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |