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 <bits/stdc++.h>
using namespace std;
int N;
vector<int> adj[200005];
vector<int> H;
void init(int _N, vector<int> _H) {
N = _N;
for(int l = 0; l < _N; l++)
H.push_back(_H[l]);
for(int l = 0; l < _N; l++) {
for(int i = l + 1; i < _N; i++) {
if(_H[i] > _H[l]) {
adj[l].push_back(i);
break;
}
}
for(int i = l - 1; i >= 0; i--) {
if(_H[i] > _H[l]) {
adj[l].push_back(i);
break;
}
}
}
}
int minimum_jumps(int A, int B, int C, int D) {
vector<int> dis(N, 1e9 + 7); queue<int> Q;
for(int l = A; l <= B; l++) {
dis[l] = 0; Q.push(l);
}
while(!Q.empty()) {
int U = Q.front(); Q.pop();
for(auto V : adj[U]) {
if(dis[U] + 1 < dis[V]) {
dis[V] = dis[U] + 1;
Q.push(V);
}
}
}
int res = 1e9 + 7;
for(int l = C; l <= D; l++)
res = min(res, dis[l]);
return (res == 1e9 + 7 ? -1 : res);
}
# | 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... |