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,dist[200005];
vector<int> lst[200005];
stack<int> s;
queue<int> q;
void init(int N, std::vector<int> H) {
n = N;
for (int i = 0; i < N; ++i) {
while (!s.empty() && H[i] >= H[s.top()]) s.pop();
if (!s.empty()) lst[i].push_back(s.top());
s.push(i);
}
while (!s.empty()) s.pop();
for (int i = N-1; i >= 0; --i) {
while (!s.empty() && H[i] >= H[s.top()]) s.pop();
if (!s.empty()) lst[i].push_back(s.top());
s.push(i);
}
}
int minimum_jumps(int A, int B, int C, int D) {
while (!q.empty()) q.pop();
for (int i = 0; i < n; ++i) dist[i] = -1;
for (int i = A; i <= B; ++i) {
dist[i] = 0;
q.push(i);
}
while (!q.empty()) {
int u = q.front(); q.pop();
if (u >= C && u <= D) return dist[u];
for (int v: lst[u]) if (dist[v] == -1) {
dist[v] = dist[u] + 1;
q.push(v);
}
}
return -1;
}
# | 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... |