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>
#include "jumps.h"
using namespace std;
vector<vector<int>> E, dis;
void init(int n, vector<int> v) {
E.assign(n, {});
for (int i = 0; i < n; i++) {
for (int j = i - 1; j >= 0; j--) {
if (v[i] < v[j]) {
E[i].push_back(j);
break;
}
}
for (int j = i + 1; j < n; j++) {
if (v[i] < v[j]) {
E[i].push_back(j);
break;
}
}
}
dis.assign(n, vector<int>(n, INT_MAX));
for (int i = 0; i < n; i++) {
queue<int> q;
q.push(i); dis[i][i] = 0;
while (!q.empty()) {
int x = q.front(); q.pop();
for (auto j : E[x]) {
if (dis[i][j] == INT_MAX) {
dis[i][j] = dis[i][x] + 1;
q.push(j);
}
}
}
}
}
int minimum_jumps(int A, int B, int C, int D) {
int mn = INT_MAX;
for (int i = A; i <= B; i++) {
for (int j = C; j <= D; j++) {
mn = min(mn, dis[i][j]);
}
}
return (mn == INT_MAX ? -1 : mn);
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |