# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
722584 | yeyso | Rainforest Jumps (APIO21_jumps) | C++14 | 4089 ms | 10652 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;
#include <vector>
vector<vector<int>> adj;
vector<int> v;
void init(int n, vector<int> h) {
// adjancency matrix
adj.assign(n, vector<int>());
v.assign(n, 0);
for(int i = 0; i < n; i ++){
// jumps to the right
for(int j = i + 1; j < n; j ++){
if(h[j] > h[i]){
adj[i].push_back(j);
break;
}
}
// jumps to the left
for(int j = i - 1; j >= 0; j --){
if(h[j] > h[i]){
adj[i].push_back(j);
break;
}
}
}
}
int minimum_jumps(int a, int b, int c, int d) {
// DISTANCE THEN NODE
queue<pair<int, int>> q;
for(int i = a; i <= b; i ++){
q.push({0, i});
}
int node = 0; int dist = 0;
int res = -1;
while(!q.empty()){
node = q.front().second;
dist = q.front().first;
q.pop();
if(!v[node]){
v[node] = 1;
for(int i = 0; i < adj[node].size(); i ++){
q.push({dist+1, adj[node][i]});
}
if(c <= node and node <= d){
res = dist;
//cout << node << " ";
}
}
}
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... |