# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
981293 | MuhammadSaram | 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.
/********************* بسم الله الرحمن الرحيم ***********************/
/******************** ٱلْحَمْدُ لِلَّٰهِ رَبِّ ٱلْعَالَمِينَ *************************/
/******************* Prophet Muhammad صلى الله عليه وسلم ************/
/*********************** وَقُل رَّبِّ زِدْنِي عِلْمًا **************************/
#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#else
#endif
#include <bits/stdc++.h>
#include "jumps.h"
using namespace std;
#define int long long
#define endl '\n'
#define in binary_search
#define ll long long
#define ld long double
#define Hey ios::sync_with_stdio(false);
#define Welcome cin.tie(NULL), cout.tie(NULL);
#define all(v) v.begin(),v.end()
const int inf = 2e5, M = 2000;
int dp[M][M];
void init(int n,int[] h)
{
if (n>M)
return;
for (int i=0;i<n;i++)
for (int j=0;j<n;j++)
dp[i][j]=(i!=j)*inf;
for (int i=0;i<n;i++)
{
int pre=i;
vector<int> v,v1;
for (int j=i+1;j<n;j++)
if (h[j]>h[pre])
v.push_back(j),pre=j,dp[i][j]=v.size();
pre=i;
for (int j=i-1;j>=0;j--)
if (h[j]>h[pre])
v1.push_back(j),pre=j,dp[i][j]=v1.size();
int p=0,p1=0;
while (p<v.size() and p2<v1.size())
{
if (h[v[p]]>h[v1[p1]])
dp[i][v[p]]=min(dp[i][v[p]],dp[i][v1[p1]]+dp[v1[p1]][v[p]]),p1++;
else
dp[i][v1[p1]]=min(dp[i][v1[p1]],dp[i][v[p]]+dp[v[p]][v1[p1]]),p++;
}
for (int j=0;j+1<v.size();j++)
dp[i][v[j+1]]=min(dp[i][v[j+1]],dp[i][v[j]]+1);
for (int j=0;j+1<v1.size();j++)
dp[i][v1[j+1]]=min(dp[i][v1[j+1]],dp[i][v1[j]]+1);
}
}
int minimum_jumps(int a, int b, int c, int d)
{
int ans=inf;
for (int j=c;j<=d;j++)
for (int i=a;i<=b;i++)
ans=min(ans,dp[i][j]);
return ans;
}