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>
#define qc ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rt return
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef long double ld;
const long long mod=1e9+7;
const long long inf=INT_MAX;
using namespace std;
ll gcd(ll a,ll b){if(b==0)rt a;rt gcd(b,a%b);}
int n;
vector<vector<int>>gph;
void init(int N,vector<int>h)
{
n=N;
gph.resize(n,vector<int>(2,-1));
for(int i=0;i<n;i++){
if(gph[i][0]==-1){
bool tkn=0;
for(int j=i-1;j>=0;j--){
if(h[j]>h[i]){
gph[i][0]=j;
break;
}
else{
if(tkn)continue;
gph[j][1]=i;
tkn=1;
}
}
}
if(gph[i][1]==-1){
bool tkn=0;
for(int j=i+1;j<n;j++){
if(h[j]>h[i]){
gph[i][1]=j;
break;
}
else{
if(tkn)continue;
gph[j][0]=i;
tkn=1;
}
}
}
}
rt;
}
int minimum_jumps(int a,int b,int c,int d)
{
queue<pair<int,int>>q; // num,ind
vector<bool>vis(n,false);
for(int i=a;i<=b;i++)q.push({0,i});
while(!q.empty()){
int x=q.front().first, y=q.front().second;
q.pop();
vis[y]=true;
if(y>=c&&y<=d)rt x;
for(auto c:gph[y]){
if(c==-1)continue;
if(!vis[c])q.push({x+1,c});
}
}
rt -1;
}
# | 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... |