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 <vector>
#include <bits/stdc++.h>
#define rep(a,b,c) for(int a=b; a<c; a++)
#define repr(a,b,c) for(int a=b-1; a>c-1; a--)
#define rep2(a,b,c,d) for(int a=b; a<c; a+=d)
#define repa(a,b) for(auto a:b)
#define fi first
#define se second
#define pb push_back
#define pq_min(a) priority_queue<a, vector<a>, greater<a>>
using namespace std;
using ll = long long int;
using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int lim=2e5+5, inf=1e9;
int h[lim], lf[lim], rg[lim], n;
void init(int N, vi H) {
n=N;
rep(i,0,n) h[i]=H[i];
stack<int> st;
rep(i,0,n){
while(st.size() && h[st.top()]<h[i]) st.pop();
if(st.size()) lf[i]=st.top();
st.push(i);
}
repr(i,n,0){
while(st.size() && h[st.top()]<h[i]) st.pop();
if(st.size()) rg[i]=st.top();
st.push(i);
}
}
int minimum_jumps(int A, int B, int C, int D) {
int dp[n], ans=inf, u;
pq_min(pii) pq;
fill(dp,dp+n,inf);
rep(i,A,B+1) dp[i]=0;
rep(i,0,D) pq.push({h[i],i});
while(pq.size()){
u=pq.top().se;
pq.pop();
dp[lf[u]]=min(dp[lf[u]],dp[u]+1);
dp[rg[u]]=min(dp[rg[u]],dp[u]+1);
}
rep(i,C,D+1) ans=min(ans,dp[i]);
if(ans==inf) return -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... |