Submission #737340

#TimeUsernameProblemLanguageResultExecution timeMemory
737340keisuke6Rainforest Jumps (APIO21_jumps)C++14
21 / 100
4099 ms13584 KiB
#include "jumps.h" #include <vector> #include <queue> using namespace std; vector<vector<int>> G(200100); int n; void init(int N, std::vector<int> H) { n = N; for(int i=0;i<N;i++){ int now = i-1; while(now >= 0 && H[now] < H[i]) now--; if(now != -1) G[i].push_back(now); now = i+1; while(now < N && H[now] < H[i]) now++; if(now != N) G[i].push_back(now); } return; } int minimum_jumps(int A, int B, int C, int D) { vector<int> dist(n,1e9); queue<int> q; for(int i=A;i<=B;i++){ dist[i] = 0; q.push(i); } while(!q.empty()){ int pos = q.front(); q.pop(); for(int x:G[pos]){ if(dist[x] != 1e9) continue; dist[x] = dist[pos] + 1; q.push(x); } } int ans = 1e9; for(int i=C;i<=D;i++) ans = min(ans,dist[i]); return (ans == 1e9 ? -1 : 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...