Submission #977500

#TimeUsernameProblemLanguageResultExecution timeMemory
977500SuPythonyRainforest Jumps (APIO21_jumps)C++17
0 / 100
4043 ms11600 KiB
#include "jumps.h" #include <bits/stdc++.h> using namespace std; vector<vector<int>> al(2*1e5,vector<int>()); void init(int n, vector<int> h) { if (h[1]>h[0]) al[0].push_back(1); if (h[n-2]>h[n-1]) al[n-1].push_back(n-2); for (int i=1; i<n-1; i++) { if (h[i-1]>h[i]) al[i].push_back(i-1); if (h[i+1]>h[i]) al[i].push_back(i+1); } } int minimum_jumps(int a, int b, int c, int d) { int ans=1e9; for (int i=a; i<=b; i++) { queue<pair<int,int>> q; q.push({i,0}); vector<int> vis(2*1e5,0); bool pos=false; int dist; while (!q.empty()) { auto u=q.front(); q.pop(); if (u.first>=c&&u.second<=d) { pos=true; dist=u.second; break; } for (int v: al[u.first]) { if (!vis[v]) { vis[v]=true; q.push({v,u.second+1}); } } } if (pos) ans=min(ans,dist); } if (ans==1e9) return -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...