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;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 2e5+5;
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
int n, a[MAXN], l_max[MAXN], r_max[MAXN];
void init(int N, vector<int> H) {
n = N;
for(int i = 1; i <= N; i++) a[i] = H[i-1];
a[0] = a[N+1] = N+1;
for(int i = 1; i <= N; i++) {
l_max[i] = i-1;
while(a[l_max[i]] < a[i]) l_max[i] = l_max[l_max[i]];
}
for(int i = N; i >= 1; i--) {
r_max[i] = i+1;
while(a[r_max[i]] < a[i]) r_max[i] = r_max[r_max[i]];
}
}
int minimum_jumps(int A, int B, int C, int D) {
A++; B++; C++; D++;
queue<int> fila;
vector<int> vis(n+2);
vis[0] = vis[n+1] = 1;
for(int i = A; i <= B; i++) fila.push(i), vis[i] = 1;
int ans = n;
while(!fila.empty()) {
int x = fila.front();
fila.pop();
if(C <= x and x <= D) ans = min(ans, vis[x] - 1);
if(!vis[l_max[x]]) vis[l_max[x]] = vis[x] + 1, fila.push(l_max[x]);
if(!vis[r_max[x]]) vis[r_max[x]] = vis[x] + 1, fila.push(r_max[x]);
}
if(ans == n) return -1;
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... |