# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
569630 | Minindu2006 | Rainforest Jumps (APIO21_jumps) | C++14 | 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;
int adj[201][201];
int inf = INT_MAX;
void init(int n, vector<int> H) {
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
adj[i][j] = inf;
for(int i=0;i<n;i++)
adj[i][i] = 0;
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
if(H[i] < H[j])
{
adj[i][j] = 1;
break;
}
for(int i=0;i<n;i++)
for(int j=i-1;j>=0;j--)
if(H[i] < H[j])
{
adj[i][j] = 1;
break;
}
int i, j, k;
for(k=0;k<n;k++)
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if (adj[i][j] > (adj[i][k] + adj[k][j])
&& (adj[k][j] != inf
&& adj[i][k] != inf))
adj[i][j] = adj[i][k] + adj[k][j];
}
}
}
}
int minimum_jumps(int A, int B, int C, int D) {
int ans = inf;
for(int i=A;i<=B;i++)
{
for(int j=C;j<=D;j++)
ans = min(adj[i][j], ans);
}
if(ans == inf)
return -1;
else
return ans;
}