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 <vector>
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> h;
const int INF = 2e6;
vector<vector<int>> adj(200, vector<int>(200, INF));
vector<vector<int>> dist(200, vector<int>(200, INF));
void init(int N, std::vector<int> H) {
n = N;
for (auto u: H) {h.push_back(u);}
h.shrink_to_fit();
for (int i=0; i<n; i++)
{
for (int j=i; j<n; j++)
{
if (h[i] < h[j]) {adj[i][j] = 1; break;};
}
for (int j=i; j>=0; j--)
{
if (h[i] < h[j]) {adj[i][j] = 1; break;};
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) dist[i][j] = 0;
else if (adj[i][j]) dist[i][j] = adj[i][j];
else dist[i][j] = INF;
}
}
for (int k = 0; k < n; k++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
}
}
}
}
int minimum_jumps(int A, int B, int C, int D) {
int answer = INF;
for (int i=A; i<=B; i++)
{
for (int j=C; j<=D; j++)
{
answer = min(answer, dist[i][j]);
}
}
return (answer >= INF ? -1 : answer);
}
# | 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... |