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 n;
int X[200005], Y[200005];
void init(int N, vector<int> H){
n = N;
stack<int>s;
for(int i=0;i<n;i++){
while(!s.empty() && H[s.top()] < H[i])s.pop();
X[i] = (s.empty() ? -1 : s.top());
s.push(i);
}
while(!s.empty())s.pop();
for(int i=n-1;i>=0;i--){
while(!s.empty() && H[s.top()] < H[i])s.pop();
X[i] = (s.empty() ? -1 : s.top());
s.push(i);
}
}
int minimum_jumps(int a, int b, int c, int d){
queue<int>q;
int dist[n+1];
for(int i=0;i<n;i++)dist[i] = 1e9;
for(int i=a;i<=b;i++)dist[i] = 0, q.push(i);
while(!q.empty()){
int x = q.front();q.pop();
if(dist[X[x]] > dist[x] + 1)dist[X[x]] = dist[x] + 1, q.push(X[x]);
if(dist[Y[x]] > dist[x] + 1)dist[Y[x]] = dist[x] + 1, q.push(Y[x]);
}
int mini = 1e9;
for(int i=c;i<=d;i++)mini = min(mini, dist[i]);
return mini;
}
# | 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... |