Submission #737336

#TimeUsernameProblemLanguageResultExecution timeMemory
737336keisuke6Rainforest Jumps (APIO21_jumps)C++14
0 / 100
1 ms336 KiB
#include "jumps.h" #include <vector> #include <queue> using namespace std; vector<vector<int>> G; int n; void init(int N, std::vector<int> H) { G.resize(N); int 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); }

Compilation message (stderr)

jumps.cpp: In function 'void init(int, std::vector<int>)':
jumps.cpp:10:7: warning: unused variable 'n' [-Wunused-variable]
   10 |   int n = N;
      |       ^
#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...