Submission #718637

#TimeUsernameProblemLanguageResultExecution timeMemory
718637lamRainforest Jumps (APIO21_jumps)C++14
0 / 100
2 ms2640 KiB
#include "jumps.h" #include <bits/stdc++.h> #include <vector> using namespace std; const int maxn = 1e5 + 10; int n,d[maxn]; int a[maxn]; vector <int> adj[maxn]; void addedge(int u, int v) { adj[u].push_back(v); } void init(int N, std::vector<int> H) { n=N; for (int i=0; i<n; i++) a[i]=H[i],adj[i].clear(); deque<int> dq; for (int i=0; i<n; i++) { while (!dq.empty()&&a[dq.back()] < a[i]) dq.pop_back(); if (!dq.empty()) addedge(i,dq.back()); } while (!dq.empty()) dq.pop_back(); for (int i=n-1; i>=0; i--) { while (!dq.empty()&&a[dq.back()] < a[i]) dq.pop_back(); if (!dq.empty()) addedge(i,dq.back()); } } int minimum_jumps(int A, int B, int C, int D) { queue<int> q; fill_n(d,n,-1); for (int i=C; i<=D; i++) { d[i]=0; q.push(i); } while (!q.empty()) { int u=q.front(); q.pop(); for (int v:adj[u]) if (d[v]==-1) { d[u]=d[v]+1; q.push(v); } } int ans=1e9; for (int i=A; i<=B; i++) if (d[i]!=-1) ans=min(ans,d[i]); if (ans==1e9) ans=-1; 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...