# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
967509 | kwongweng | Rainforest Jumps (APIO21_jumps) | C++17 | 4088 ms | 17456 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
typedef vector<vector<ll>> vll;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define ms memset
#define fi first
#define se second
const int mxn = 2e5;
int n; vi a, g[mxn];
void init(int N, vi H) {
n=N; a=H;
vi lf(n); vi rg(n);
stack<int> S;
FOR(i,0,n){
while (!S.empty() && a[S.top()] < a[i]){
S.pop();
}
if (S.empty()) lf[i] = -1;
else lf[i] = S.top();
S.push(i);
}
while (!S.empty()) S.pop();
ROF(i,n-1,0){
while (!S.empty() && a[S.top()] < a[i]){
S.pop();
}
if (S.empty()) rg[i] = n;
else rg[i] = S.top();
S.push(i);
}
FOR(i,0,n){
if (lf[i] != -1){
g[lf[i]].pb(i);
}
if (rg[i] != n){
g[rg[i]].pb(i);
}
}
}
int minimum_jumps(int A, int B, int C, int D) {
vi bfs, used(n), dist(n);
FOR(i,C,D+1){
bfs.pb(i); used[i]=1;
}
FOR(i,0,bfs.size()){
int u = bfs[i];
for (int v : g[u]){
if (used[v]) continue;
used[v]=1; dist[v] = dist[u]+1;
bfs.pb(v);
}
}
int ans = n;
FOR(i,A,B+1){
if (dist[i]) ans = min(ans, dist[i]);
}
if (ans==n) ans=-1;
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |