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<bits/stdc++.h>
using namespace std;
int lft[200007],rgt[200007];
bool czy1=1;
bool odw[200007];
int n;
void init(int N,vector<int>v){
n=N;
stack<int>s;
lft[200006]=200006;
rgt[200006]=200006;
//s.push(n);
for(int i=0;i<n;i++){
lft[i]=200006;
rgt[i]=200006;
}
//return;
for(int i=0;i<n;i++){
if(s.empty() || v[s.top()]>v[i])
s.push(i);
else{
rgt[s.top()]=i;
s.pop();
i--;
}
}
while(s.size()>0) s.pop();
for(int i=n-1;i>=0;i--){
if(s.empty() || v[s.top()]>v[i])
s.push(i);
else{
czy1=0;
lft[s.top()]=i;
s.pop();
i++;
}
}
//for(int i=0;i<n;i++)
//cout<<lft[i]<<" "<<rgt[i]<<"\n";
}
int minimum_jumps(int a,int b,int c,int d){
//if(czy1)
// return c-b;
odw[200006]=1;
int ans[n];
for(int i=0;i<n;i++){ odw[i]=0; ans[i]=200007;}
for(int i=a;i<=b;i++) odw[i]=1;
priority_queue<pair<int,int>>pq;
for(int i=a;i<=b;i++){
pq.push({0,i});
}
while(!pq.empty()){
pair<int,int>pom=pq.top();
pq.pop();
ans[pom.second]=pom.first;
if(!odw[lft[pom.second]]){
odw[lft[pom.second]]=1;
pq.push({pom.first+1,lft[pom.second]});
}
if(!odw[rgt[pom.second]]){
odw[rgt[pom.second]]=1;
pq.push({pom.first+1,rgt[pom.second]});
}
//return 0;
}
int mn=200007;
for(int i=c;i<=d;i++){
mn=min(mn,ans[i]);
}
if(mn==200007)
mn=-1;
return mn;
}
# | 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... |