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>
#include<iostream>
#include<cmath>
#include<stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b); i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
#define mp make_pair
#define pb push_back
#define rsz resize
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
#define f first
#define s second
#define out(x) cout<<x<<'\n';
#define in(x) cin>>x;
#define inarr(a,x,y) for(int i=x;i<y;i++){cin>>a[i];}
#define incor(a,x,y) for(int i=x;i<y;i++){cin>>a[i].f>>a[i].s;}
const int mod = 1e9 + 7;
const int maxn = 2e3 + 5;
int h[maxn], lft[maxn], rgt[maxn], dp[maxn], n;
int ok = 1;
void init(int N, std::vector<int> H)
{
for (int i = 0; i < N; i++) {
if (H[i] != i + 1) ok = 0;
}
if (ok == 1) return;
n = N;
FOR(i, 0, n)
h[i] = H[i];
FOR(i, 0, n)
{
lft[i] = rgt[i] = i;
for (int j = i - 1; j >= 0; --j)
if (h[j] > h[i])
{
lft[i] = j;
break;
}
for (int j = i + 1; j < n; ++j)
if (h[j] > h[i])
{
rgt[i] = j;
break;
}
}
}
int minimum_jumps(int a, int b, int c, int d)
{
if (ok == 1) {
if (c <= b) return 0;
else return c - b;
}
FOR(i, 0, n)
dp[i] = mod;
queue<int> q;
FOR(i, a, b + 1)
{
dp[i] = 0;
q.push(i);
}
while (sz(q))
{
int u = q.front(); q.pop();
if (u >= c && u <= d) return dp[u];
if (dp[lft[u]] == mod)
{
dp[lft[u]] = dp[u] + 1;
q.push(lft[u]);
}
if (dp[rgt[u]] == mod)
{
dp[rgt[u]] = dp[u] + 1;
q.push(rgt[u]);
}
}
return -1;
}
# | 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... |