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 "jumps.h"
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 12345;
vector<vector<int>> dist;
void init(int n, vector<int> h) {
dist = vector<vector<int>>(n, vector<int>(n, INF));
for (int i = 0; i < n; i++) {
dist[i][i] = 0;
}
for (int i = 0; i < n; i++) {
for (int j = i - 1; j >= 0; j--) {
if (h[j] > h[i]) {
dist[i][j] = 1;
break;
}
}
for (int j = i + 1; j < n; j++) {
if (h[j] > h[i]) {
dist[i][j] = 1;
break;
}
}
}
for (int m = 0; m < n; m++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
dist[i][j] = min(dist[i][j], dist[i][m] + dist[m][j]);
}
}
}
}
int minimum_jumps(int l0, int r0, int l1, int r1) {
r0++; r1++;
int res = INF;
for (int i = l0; i < r0; i++) {
for (int j = l1; j < r1; j++) {
res = min(res, dist[i][j]);
}
}
if (res == INF) return -1;
return res;
}
# | 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... |