# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
413616 | daniel920712 | Rainforest Jumps (APIO21_jumps) | C++14 | 4070 ms | 29076 KiB |
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 <vector>
#include <queue>
#include <stack>
#include <stdio.h>
using namespace std;
int r[25][200005];
int l[25][200005];
int Pow[25];
stack < int > all;
vector < int > high;
void init(int N, std::vector<int> H)
{
high=H;
int i,j,k;
Pow[0]=1;
for(i=1;i<=20;i++) Pow[i]=Pow[i-1]*2;
for(i=0;i<=20;i++)
{
for(j=0;j<N;j++)
{
r[i][j]=j;
l[i][j]=j;
}
}
for(i=0;i<N;i++)
{
while(!all.empty()&&H[all.top()]<H[i])
{
r[0][all.top()]=i;
all.pop();
}
all.push(i);
}
while(!all.empty()) all.pop();
for(i=N-1;i>=0;i--)
{
while(!all.empty()&&H[all.top()]<H[i])
{
l[0][all.top()]=i;
all.pop();
}
all.push(i);
}
while(!all.empty()) all.pop();
for(i=1;i<=20;i++)
{
for(j=0;j<N;j++)
{
for(k=l[i-1][j];k<=r[i-1][j];k++)
{
l[i][j]=min(l[i][j],l[i-1][k]);
r[i][j]=max(r[i][j],r[i-1][k]);
}
}
}
return ;
}
int minimum_jumps(int A, int B, int C, int D)
{
int ans=0,now=A,i,j,ll=A,rr=B,x,y,ok=0;
for(i=A;i<=B;i++) for(j=C;j<=D;j++) ok=ok||(high[j]>high[i]);
if(!ok) return -1;
if(!(B<C||D<A)) return 0;
for(i=20;i>=0;i--)
{
x=ll;
y=rr;
for(j=ll;j<=rr;j++)
{
x=min(x,l[i][j]);
y=max(y,r[i][j]);
}
//printf("%d %d %d %d %d\n",ll,rr,x,y,i);
if(y<C||D<x)
{
ans+=Pow[i];
ll=x;
rr=y;
}
}
x=ll;
y=rr;
for(j=ll;j<=rr;j++)
{
x=min(x,l[0][j]);
y=max(y,r[0][j]);
}
//printf("%d %d %d %d\n",ll,rr,x,y);
if(y<C||D<x)
{
return -1;
}
return ans+1;
}
Compilation message (stderr)
# | 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... |