Submission #1047560

#TimeUsernameProblemLanguageResultExecution timeMemory
1047560Marco_EscandonRainforest Jumps (APIO21_jumps)C++11
33 / 100
4066 ms85796 KiB
#include "jumps.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; ll n; vector<vector<ll>>PD,PI; void init(int N, std::vector<int> h) { n=N; stack<ll> q; PD.assign(24,vector<ll>(n+6,n+5)); PI.assign(24,vector<ll>(n+6,-1)); for(int i=0; i<n; i++) { while(!q.empty()&&h[i]>h[q.top()]) { PD[0][q.top()]=i; q.pop(); } if(!q.empty()) PI[0][i]=q.top(); q.push(i); } for(int i=1; i<24; i++) for(int j=0; j<n+6; j++) PD[i][j]=PD[i-1][PD[i-1][j]]; } vector<ll> cache; ll asd,asd2; ll asdf; ll sol(ll node) { if(node>asd2||node<0) return 1e9; if(node>=asd) return 0; if(cache[node]!=-1) return cache[node]; ll o1=(asdf>PI[0][node])+sol(PI[0][node]),o2=1+sol(PD[0][node]); return cache[node]=min(o1,o2); } int minimum_jumps(int A, int B, int C, int D) { cache.assign(n+6,-1); asd=C; asd2=D; asdf=A; ll bs=sol(B); if(bs>=1e9) bs=-1; return bs; }
#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...