Submission #542309

#TimeUsernameProblemLanguageResultExecution timeMemory
542309penguin133Rainforest Jumps (APIO21_jumps)C++14
0 / 100
4035 ms2808 KiB
#include "jumps.h" #include <bits/stdc++.h> using namespace std; int n; int X[200005], Y[200005]; void init(int N, vector<int> H){ n = N; stack<int>s; for(int i=0;i<n;i++){ while(!s.empty() && H[s.top()] < H[i])s.pop(); X[i] = (s.empty() ? -1 : s.top()); s.push(i); } while(!s.empty())s.pop(); for(int i=n-1;i>=0;i--){ while(!s.empty() && H[s.top()] < H[i])s.pop(); X[i] = (s.empty() ? -1 : s.top()); s.push(i); } } int minimum_jumps(int a, int b, int c, int d){ queue<int>q; int dist[n+1]; for(int i=0;i<n;i++)dist[i] = 1e9; for(int i=a;i<=b;i++)dist[i] = 0, q.push(i); while(!q.empty()){ int x = q.front();q.pop(); if(X[x] != -1 && dist[X[x]] > dist[x] + 1)dist[X[x]] = dist[x] + 1, q.push(X[x]); if(Y[x] != -1 && dist[Y[x]] > dist[x] + 1)dist[Y[x]] = dist[x] + 1, q.push(Y[x]); } int mini = 1e9; for(int i=c;i<=d;i++)mini = min(mini, dist[i]); return mini; }
#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...