Submission #1223462

#TimeUsernameProblemLanguageResultExecution timeMemory
1223462KALARRYRainforest Jumps (APIO21_jumps)C++20
0 / 100
4016 ms4108 KiB
//chockolateman #include<bits/stdc++.h> using namespace std; int n,l[200005],r[200005],dist[200005],a[200005]; bool used[200005]; void init(int N, std::vector<int> H) { for(int i = 1 ; i <= N ; i++) a[i] = H[i-1]; n = N; stack<int> order; order.push(N+1); for(int i = 1 ; i <= N ; i++) { while(H[i-1] > order.top()) order.pop(); l[a[i]] = order.top(); order.push(a[i]); } while(!order.empty()) order.pop(); order.push(N+1); for(int i = N ; i >= 1 ; i--) { while(H[i-1] > order.top()) order.pop(); r[a[i]] = order.top(); order.push(a[i]); } } int ans(long long v,long long targ) { if(v==targ) return 0; if(min(l[v],r[v]) > a[targ]) return 1e9; long long res; if(max(l[v],r[v]) <= targ) res = ans(max(l[v],r[v]),targ) + 1; else res = ans(min(l[v],r[v]),targ) + 1; return res; } int minimum_jumps(int A, int B, int C, int D) { A++; B++; C++; D++; int ret = 1e9; for(int i = A ; i <= B ; i++) for(int j = C ; j <= D ; j++) { ret = min(ret,ans(a[i],a[j])); } if(ret > n) ret = -1; return ret; }
#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...