# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
983630 | hocln | Rainforest Jumps (APIO21_jumps) | C++17 | 0 ms | 0 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 <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=2e5+9,M=2e18+9,mod=1e9+7;
bool vis[N];
pair<ll,ll>p;
vector<ll>v[N];
ll a[N],n,x,y,z;
priority_queue<pair<ll,ll>>q;
void init(int m,vector<int>h)
{
n=m;
for(ll i=0;i<n;++i)a[i]=h[i];
for(ll i=0;i<n;++i)
{
for(ll j=i-1;j>=0;--j)
{
if(a[j]>a[i])
{
v[i].push_back(j);
break;
}
}
for(ll j=i+1;j<n;++j)
{
if(a[j]>a[i])
{
v[i].push_back(j);
break;
}
}
}
}
int minimum_jumps(int A, int B, int C, int D)
{
x=-1;
for(ll i=A;i<=B;++i)
{
if(!vis[i])
{
q.push({0,i});
vector<ll>d(n,inf);
d[i] = 0;
while(q.size())
{
p=q.top();
q.pop();
if(C<=p.second && p.second<=D)
{
x=(x==-1?d[p.second]:min(x,d[p.second]));
continue;
}
for(auto j:v[p.first]) if(d[j] > d[p.second] + 1) d[j]=d[p.second] + 1,q.push({-d[j],j});
}
}
}
return x;
}