This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
for(int i=1;i<=N;i++)assert(in[i]),assert(out[i]);
//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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |