Submission #1099639

#TimeUsernameProblemLanguageResultExecution timeMemory
1099639Saul0906Rainforest Jumps (APIO21_jumps)C++14
0 / 100
4034 ms5072 KiB
#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 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; fill(dp,dp+n,inf); rep(i,A,B+1) dp[i]=0; repr(i,B+1,A) dp[lf[i]]=min(dp[lf[i]],dp[i]+1); rep(i,0,D) dp[rg[i]]=min(dp[rg[i]],dp[i]+1); rep(i,C,D+1) ans=min(ans,dp[i]); if(ans==inf) return -1; return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...