Submission #980313

#TimeUsernameProblemLanguageResultExecution timeMemory
980313vjudge1Rainforest Jumps (APIO21_jumps)C++17
0 / 100
1 ms2392 KiB
#include <bits/stdc++.h> using namespace std; // #define int long long #define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define nl "\n" int n; vector<int> h; const int maxn = 200005; pair<int, int> adj[maxn]; //left, right int dist[maxn]; void init(int N, vector<int> H){ n = N; h = H; stack<int> tree; for(int i=0; i<n; i++){ while(!tree.empty() && h[tree.top()]<h[i]) tree.pop(); if(!tree.empty()) adj[i].first = tree.top(); else adj[i].first = -1; tree.push(i); } while(!tree.empty()) tree.pop(); for(int i=n-1; i>=0; i--){ while(!tree.empty() && h[tree.top()]<h[i]) tree.pop(); if(!tree.empty()) adj[i].second = tree.top(); else adj[i].second = -1; tree.push(i); } } int minimum_jumps(int A, int B, int C, int D){ queue<int> q; for (int i=A; i<=B; i++) { q.push(i); dist[i] = 0; } while(!q.empty()){ int v = q.front(); q.pop(); if(C<=v && v<=D){ return dist[v]; } int i = adj[v].first; if(i!=-1 && dist[i]>dist[v]+1){ dist[i] = dist[v]+1; q.push(i); } int j = adj[v].second; if(j!=-1 && dist[j]>dist[v]+1){ dist[j] = dist[v]+1; q.push(j); } } return -1; }
#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...