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;
bool sub1 = true;
int adj[205][205];
void init(int N, std::vector<int> H) {
for(int i = 0;i < N-1;i++){
if(H[i+1]!=H[i]+1) sub1 = false;
}
if(sub1) return;
for(int i = 0;i < N;i++){
for(int j = 0;j < N;j++){
adj[i][j] = 1e9;
}
adj[i][i] = 0;
}
for(int i = 0;i < N;i++){
for(int j = i-1;~j;j--){
if(H[j]>H[i]){
adj[i][j] = 1;
break;
}
}
for(int j = i+1;j < N;j++){
if(H[j]>H[i]){
adj[i][j] = 1;
break;
}
}
}
for(int k = 0;k < N;k++){
for(int i = 0;i < N;i++){
for(int j = 0;j < N;j++){
adj[i][j] = min(adj[i][k]+adj[k][j],adj[i][j]);
}
}
}
}
int minimum_jumps(int A, int B, int C, int D) {
if(sub1) return min({abs(A-D),abs(A-C),abs(B-C),abs(B-D)});
int ans = 1e9;
for(int i = A;i <= B;i++){
for(int j = C;j <= D;j++){
ans = min(adj[i][j],ans);
}
}
return (ans==1e9 ? -1 : ans);
}
//Subtask 2 => run floyd once
# | 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... |