# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
971440 | Pannda | Rainforest Jumps (APIO21_jumps) | C++17 | 0 ms | 0 KiB |
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 brute_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 brute_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;
}