이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v,a,b;
void init(int N, vector<int> H) {
n=N;
v=H;
a.resize(n,-1);
b.resize(n,-1);
vector<int> st;
for(int i=0;i<n;i++){
while(st.size()&&v[st.back()]<v[i]){
st.pop_back();
}
a[i]=(st.size()?st.back():-1);
st.push_back(i);
}
st.clear();
for(int i=n-1;i>=0;i--){
while(st.size()&&v[st.back()]<v[i]){
st.pop_back();
}
b[i]=(st.size()?st.back():-1);
st.push_back(i);
}
for(int i=0;i<n;i++){
if(a[i]==-1)swap(a[i],b[i]);
else if(b[i]==-1)continue;
else {
if(v[a[i]]<v[b[i]]){
swap(a[i],b[i]);
}
}
}
}
int f(int A, int C) {
int ans=0;
int now=A;
while(now!=C){
if(v[now]>v[C])return 1e9;
if(a[now]==-1&&b[now]==-1){
return 1e9;
}
if(a[now]==-1)now=b[now];
else if(b[now]==-1)now=a[now];
else{
int g1=a[now],g2=b[now];
if(v[g1]<=v[C])now=g1;
else if(v[g2]<=v[C])now=g2;
else return 1e9;
}
ans++;
}
return ans;
}
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,f(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... |