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 long double ld;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
#define PB push_back
#define MP make_pair
#define all(a) (a).begin(), (a).end()
#define endl '\n'
#define dbg(x) cerr << '[' << #x << ": " << x << "]\n"
#define dbg2(x, y) cerr << '[' << #x << ": " << x << ", " << #y << ": " << y << "]\n"
#define YES cout << "YES\n"
#define NO cout << "NO\n"
const ll INF = (ll)2e18 + 1386;
const ld EPS = 0.000000000000001;
const int MOD = 1e9 + 7;
inline int _add(int a, int b){ int res = a + b; return (res >= MOD ? res - MOD : res); }
inline int _neg(int a, int b){ int res = (abs(a - b) < MOD ? a - b : (a - b) % MOD); return (res < 0 ? res + MOD : res); }
inline int _mlt(ll a, ll b){ return (a * b % MOD); }
inline void fileIO(string i, string o){ freopen(i.c_str(), "r", stdin); freopen(o.c_str(), "w", stdout); }
const int MAXN = 202;
int n;
int a[MAXN], dist[MAXN][MAXN], cand[MAXN][2];
bitset<MAXN> mark;
void bfs(int src){
mark.reset();
queue<int> q;
q.push(src);
mark[src] = 1;
dist[src][src] = 0;
while (!q.empty()){
int v = q.front();
q.pop();
for (int i = 0; i < 2; i++){
if (cand[v][i] != 0 && !mark[cand[v][i]]){
mark[cand[v][i]] = 1;
dist[src][cand[v][i]] = dist[src][v] + 1;
q.push(cand[v][i]);
}
}
}
}
void init(int N, std::vector<int> H) {
n = N;
VI agha;
for (int i = 1; i <= n; i++){
a[i] = H[i - 1];
while (!agha.empty() && a[i] > a[agha.back()]){
agha.pop_back();
}
if (!agha.empty()) cand[i][0] = agha.back();
agha.PB(i);
for (int j = 1; j <= n; j++){
dist[i][j] = INT_MAX;
}
}
agha.clear();
for (int i = n; i >= 1; i--){
while (!agha.empty() && a[i] > a[agha.back()]){
agha.pop_back();
}
if (!agha.empty()) cand[i][1] = agha.back();
agha.PB(i);
}
for (int i = 1; i <= n; i++) bfs(i);
}
int minimum_jumps(int A, int B, int C, int D) {
int ans = INT_MAX;
A++, B++, C++, D++;
for (int i = A; i <= B; i++){
for (int j = C; j <= D; j++){
ans = min(ans, dist[i][j]);
}
}
return ans == INT_MAX ? -1 : ans;
}
# | 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... |