Submission #542314

#TimeUsernameProblemLanguageResultExecution timeMemory
542314penguin133Rainforest Jumps (APIO21_jumps)C++14
37 / 100
4059 ms4248 KiB
#include "jumps.h" #include <bits/stdc++.h> using namespace std; int n, flag; 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); } flag = 1; for(int i=0;i<n;i++)if(H[i] != i + 1)flag= 0; while(!s.empty())s.pop(); for(int i=n-1;i>=0;i--){ while(!s.empty() && H[s.top()] < H[i])s.pop(); Y[i] = (s.empty() ? -1 : s.top()); s.push(i); } } int minimum_jumps(int a, int b, int c, int d){ if(flag){ if(a > d)return -1; else if(b >= c || a >= d)return 0; else return c-b; } 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 == 1e9 ? -1 : 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...