Submission #1099640

#TimeUsernameProblemLanguageResultExecution timeMemory
1099640Saul0906Rainforest Jumps (APIO21_jumps)C++14
0 / 100
4086 ms6164 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 #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(int) pq; fill(dp,dp+n,inf); rep(i,A,B+1) dp[i]=0; rep(i,0,D) pq.push(i); while(pq.size()){ u=pq.top(); 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 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...