이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "jumps.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2*1e3+7;
vector <int> a;
vector <int> g[N];
bool u[N], u1[N];
int dp[N][N];
void dfs(int i, int v, int res=0){
u[v]=u1[v]=1;
dp[i][v]=min(dp[i][v], res);
for (auto l:g[v]){
if (!u[l]) dfs(i, l, res+1);
}
u[v]=0;
}
void init(int N, std::vector<int> H) {
int n=N;
a=H;
vector <int> v;
for (int i=n-1;i>=0;i--){
while (!v.empty() && a[i] > a[v.back()]) v.pop_back();
if (!v.empty()) g[i].push_back(v.back());
v.push_back(i);
}
v.clear();
for (int i=0;i<n;i++){
while (!v.empty() && a[i] > a[v.back()]) v.pop_back();
if (!v.empty()) g[i].push_back(v.back());
v.push_back(i);
}
for (int i=0;i<n;i++){
for (int j=0;j<n;j++) dp[i][j]=1e9;
fill(u1, u1+n+10, 0);
for (int j=0;j<n;j++){
if (!u1[i]){
dfs(i, i, 0);
}
}
}
/* for (int i=0;i<n;i++){
for (int j=0;j<n;j++) cout << dp[i][j] <<" ";
cout <<"\n";
}*/
}
int minimum_jumps(int A, int B, int C, int D) {
int ans=1e9;
for (int i=A;i<=B;i++){
for (int j=C;j<=D;j++){
ans=min(ans, dp[i][j]);
}
}
if (ans == 1e9) ans=-1;
return 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... |