Submission #979699

#TimeUsernameProblemLanguageResultExecution timeMemory
979699Darren0724Rainforest Jumps (APIO21_jumps)C++17
0 / 100
4046 ms344 KiB
#include "jumps.h" #include <bits/stdc++.h> using namespace std; int n; vector<int> v,a,b; void init(int N, vector<int> H) { n=N; v=H; a.resize(n,-1); b.resize(n,-1); vector<int> st; for(int i=0;i<n;i++){ while(st.size()&&v[st.back()]<v[i]){ st.pop_back(); } a[i]=(st.size()?st.back():-1); } st.clear(); for(int i=n-1;i>=0;i--){ while(st.size()&&v[st.back()]<v[i]){ st.pop_back(); } b[i]=(st.size()?st.back():-1); } } int minimum_jumps(int A, int B, int C, int D) { int ans=0; if(v[A]>v[B])return -1; int now=A; while(now!=C){ if(a[now]!=-1)now=b[now]; else if(b[now]!=-1)now=a[now]; else{ int g1=a[now],g2=b[now]; if(v[g1]<v[g2])swap(g1,g2); if(v[g1]<=v[C])now=g1; else now=g2; } ans++; } 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...