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 "jumps.h"
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
using namespace std;
stack <int>st;
int v[200005];
vector<int>adj[200005];
int n;
void init(int N, vector<int> H)
{
int i;
n=N;
for(i=1; i<=n; i++)
{
v[i]=H[i-1];
}
v[0]=1e8;
st.push(0);
for(i=1; i<=n; i++)
{
while(v[i]>v[st.top()])
{
adj[st.top()].push_back(i);
st.pop();
}
st.push(i);
}
while(st.size())
{
st.pop();
}
st.push(n+1);
v[n+1]=1e8;
for(i=n; i>=1; i--)
{
while(v[i]>v[st.top()])
{
adj[st.top()].push_back(i);
st.pop();
}
st.push(i);
}
while(st.size())
{
st.pop();
}
}
queue<int>qu;
int rasp[200005];
int minimum_jumps(int a, int b, int c, int d)
{
int i,k,curr;
a++;
b++;
c++;
d++;
for(i=1;i<=n;i++)
{
rasp[i]=1e8;
}
if(a>b)
{
swap(a,b);
}
if(c>d)
{
swap(c,d);
}
for(i=a;i<=b;i++)
{
qu.push(i);
rasp[i]=0;
}
while(qu.size())
{
curr=qu.front();
qu.pop();
if(curr>=c && curr<=d)
{
while(qu.size())
{
qu.pop();
}
return rasp[curr];
}
for(i=0;i<adj[curr].size();i++)
{
k=adj[curr][i];
if(rasp[k]>rasp[curr]+1)
{
rasp[k]=rasp[curr]+1;
qu.push(k);
}
}
}
return -1;
}
vector<int>vect;
/*int main ()
{
int ne,i,q,a,b,c,d,x;
cin>>ne;
for(i=1;i<=ne;i++)
{
cin>>x;
vect.push_back(x);
}
init(ne,vect);
cin>>q;
for(i=1;i<=q;i++)
{
cin>>a>>b>>c>>d;
cout<<minimum_jumps(a,b,c,d);
}
}
*/
Compilation message (stderr)
jumps.cpp: In function 'int minimum_jumps(int, int, int, int)':
jumps.cpp:89:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | for(i=0;i<adj[curr].size();i++)
| ~^~~~~~~~~~~~~~~~~
# | 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... |