This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC target("avx512f")
#include "jumps.h"
#include <vector>
#include <queue>
using namespace std;
vector<vector<int>> G(200100);
int n;
void init(int N, std::vector<int> H) {
n = N;
for(int i=0;i<N;i++){
int now = i-1;
while(now >= 0 && H[now] < H[i]) now--;
if(now != -1) G[i].push_back(now);
now = i+1;
while(now < N && H[now] < H[i]) now++;
if(now != N) G[i].push_back(now);
}
return;
}
int minimum_jumps(int A, int B, int C, int D) {
vector<int> dist(n,1e9);
queue<int> q;
for(int i=A;i<=B;i++){
dist[i] = 0;
q.push(i);
}
while(!q.empty()){
int pos = q.front();
q.pop();
for(int x:G[pos]){
if(dist[x] != 1e9) continue;
dist[x] = dist[pos] + 1;
q.push(x);
}
}
int ans = 1e9;
for(int i=C;i<=D;i++) ans = min(ans,dist[i]);
return (ans == 1e9 ? -1 : 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... |