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>
#include "jumps.h"
using namespace std;
int n, dp[200005];
vector<int> h;
void init(int N, vector<int> H){
n = N;
for(int x : H) h.push_back(x);
}
int solve(int s, int c, int d){
if(c <= s && s <= d) return 0;
if(dp[s] != -1) return dp[s];
int ans = INT_MAX;
for(int i = s + 1; i < n; i++){
if(h[i] > h[s]){
ans = min(ans, solve(i, c, d) + 1);
break;
}
}
for(int i = s - 1; i > -1; i--){
if(h[i] > h[s]){
ans = min(ans, solve(i, c, d) + 1);
break;
}
}
return dp[s] = ans;
}
int minimum_jumps(int a, int b, int c, int d){
memset(dp, -1, sizeof(dp));
int ans = INT_MAX;
for(int i = a; i <= b; i++) ans = min(ans, solve(i, c, d));
if(ans == INT_MAX) ans = -1;
return ans;
}
# | 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... |