Submission #1120002

#TimeUsernameProblemLanguageResultExecution timeMemory
1120002dsyzRainforest Jumps (APIO21_jumps)C++17
33 / 100
4070 ms34188 KiB
#include <bits/stdc++.h> #include "jumps.h" using namespace std; using ll = long long; #define MAXN (1000005) ll N; vector<ll> v[MAXN]; void init(int n, vector<int> H){ N = n; stack<ll> s; for(ll i = 0;i < N;i++){ while(!s.empty() && H[s.top()] < H[i]){ s.pop(); } if(!s.empty()){ v[i].push_back(s.top()); } s.push(i); } while(!s.empty()){ s.pop(); } for(ll i = N - 1;i >= 0;i--){ while(!s.empty() && H[s.top()] < H[i]){ s.pop(); } if(!s.empty()){ v[i].push_back(s.top()); } s.push(i); } } int minimum_jumps(int A, int B, int C, int D){ queue<ll> q; ll dist[N]; memset(dist,-1,sizeof(dist)); for(ll i = A;i <= B;i++){ q.push(i); dist[i] = 0; } while(!q.empty()){ ll x = q.front(); q.pop(); for(auto u : v[x]){ if(dist[u] == -1){ q.push(u); dist[u] = dist[x] + 1; } } } ll mini = 1e18; for(ll i = C;i <= D;i++){ if(dist[i] == -1) continue; mini = min(mini,dist[i]); } if(mini == 1e18) return -1; else 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...