Submission #1101271

#TimeUsernameProblemLanguageResultExecution timeMemory
1101271WarinchaiRainforest Jumps (APIO21_jumps)C++14
0 / 100
208 ms9032 KiB
#include "jumps.h" #include<bits/stdc++.h> #include <vector> using namespace std; int n; int l[200005]; int r[200005]; int in[200005]; int out[200005]; int tme=0; int h[200005]; void dfs(int u,int p=0){ in[u]=++tme; //cerr<<u<<":"<<l[u]<<" "<<r[u]<<"\n"; h[u]=h[p]+1; if(l[u])dfs(l[u],u); if(r[u])dfs(r[u],u); out[u]=tme; } void init(int N, std::vector<int> H) { n=N; stack<int>s; int rt=0; for(int i=1;i<=N;i++){ while(!s.empty()&&H[i-1]>H[s.top()-1])l[i]=s.top(),s.pop(); if(s.empty())rt=i; else r[s.top()]=i; s.push(i); } dfs(rt); //cerr<<"\n\n"; } int minimum_jumps(int A, int B, int C, int D) { A++,B++,C++,D++; //cerr<<"IN ANS:"<<A<<' '<<C<<"\n"; //cerr<<in[A]<<" "<<out[A]<<", "<<in[C]<<" "<<out[C]<<"\n"; if(in[A]>=in[C]&&in[A]<=out[C]){ //cerr<<h[C]<<"-"<<h[A]<<"\n"; return h[A]-h[C]; } return -1; }
#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...