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;
int sb1 = 1;
void init(int n, vector<int> H) {
for(int i=0;i<n-1;i++)
if(H[i + 1] != H[i] + 1)
{
sb1 = 0;
break;
}
if(sb1)
return;
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) {
if(sb1)
return C - B;
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;
}
# | 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... |