# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
439022 | aris12345678 | Rainforest Jumps (APIO21_jumps) | C++14 | 1168 ms | 2624 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 <bits/stdc++.h>
using namespace std;
const int mxN = 200005;
bool sub1 = false;
vector<int> height;
void init(int n, vector<int> h) {
if(is_sorted(h.begin(), h.end()))
sub1 = true;
height = h;
return;
}
int bfs(int i, int end) {
int n = int(height.size());
queue<pair<int, int> > q;
q.push({i, 0});
while(!q.empty()) {
int u = q.front().first, jumps = q.front().second;
q.pop();
if(u == end)
return jumps;
int j = u;
while(j >= 0 && height[j] <= height[u])
j--;
if(j >= 0)
q.push({j, jumps+1});
j = u;
while(j < n && height[j] <= height[u])
j++;
if(j < n)
q.push({j, jumps+1});
}
assert(true);
}
int minimum_jumps(int a, int b, int c, int d) {
if(sub1)
return c-b;
else {
int ans = INT_MAX;
for(int i = a; i <= b; i++) {
int pos = i;
for(int j = c; j <= d; j++) {
if(height[j] < height[i]) continue;
int jumps = bfs(pos, j);
ans = min(ans, jumps);
}
}
}
}
/*
3 2 1 6 4 5 7
(1, 3)
(5, 6)
*/
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... |