# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1047477 | SN0WM4N | Rainforest Jumps (APIO21_jumps) | C++14 | 4086 ms | 4184 KiB |
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;
vector<int> v;
vector<int> m_sig, m_prev;
void init(int N, std::vector<int> H) {
v = H;
m_sig.resize(N);
m_prev.resize(N);
for (int i = N - 1; i >= 0; i --) {
m_sig[i] = i;
m_prev[i] = i;
for (int j = i; j < N; j ++) {
if (H[j] > H[i]) {
m_sig[i] = j;
break;
}
}
for (int j = i; j >= 0; j --) {
if (H[j] > H[i]) {
m_prev[i] = j;
break;
}
}
}
}
int minimum_jumps(int A, int B, int C, int D) {
int res = 1e9;
for (int i = A; i <= B; i ++) {
queue<pair<int, int>> q;
q.push({i, 0});
vector<int> vis(v.size(), 1e9);
int ans = 1e9;
while (!q.empty()) {
auto [x, d] = q.front();
q.pop();
if (vis[x] <= d)
continue;
if (C <= x && x <= D) {
ans = d;
break;
}
vis[x] = d;
q.push({m_sig[x], d + 1});
q.push({m_prev[x], d + 1});
}
res = min(res, ans);
}
if (res == 1e9)
res = -1;
return res;
}
Compilation message (stderr)
# | 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... |