이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "jumps.h"
#include <bits/stdc++.h>
#ifndef EVAL
#include "stub.cpp"
#endif
using namespace std;
int n;
bool h=0;
vector<int> a;
int b[200005],c[200005];
void init(int N, vector<int> H) {
n=N;
a=H;
for(int i=0;i<n;i++){
if(i){
if(H[i]!=H[i-1]+1){
h=1;
break;
}
}
}
if(h==0){
return;
}
deque<int> s;
for(int i=0;i<n;i++){
while(!s.empty() && a[s.back()]<a[i]){
s.pop_back();
}
if(s.empty()){
b[i]=-1;
}
else{
b[i]=s.back();
}
s.push_back(i);
}
s.clear();
for(int i=n-1;i>=0;i--){
while(!s.empty() && a[s.back()]<a[i]){
s.pop_back();
}
if(s.empty()){
c[i]=-1;
}
else{
c[i]=s.back();
}
s.push_back(i);
}
}
int ans[200005];
int minimum_jumps(int A, int B, int C, int D) {
if(h==0){
return C-B;
}
else{
for(int i=0;i<n;i++){
ans[i]=1e9;
}
queue<int> q;
for(int i=A;i<=B;i++){
ans[i]=0;
q.push(i);
}
while(!q.empty()){
int to=q.front();
q.pop();
if(b[to]!=-1 && ans[b[to]]>ans[to]+1){
ans[b[to]]=ans[to]+1;
q.push(b[to]);
}
if(c[to]!=-1 && ans[c[to]]>ans[to]+1){
ans[c[to]]=ans[to]+1;
q.push(c[to]);
}
}
int k=1e9;
for(int i=C;i<=D;i++){
k=min(k,ans[i]);
}
if(k==1e9){
return -1;
}
else{
return k;
}
}
}
# | 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... |