This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |