이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
vector<vector<ll>>PD,PI;
void init(int N, std::vector<int> h)
{
n=N; stack<ll> q;
PD.assign(24,vector<ll>(n+6,n+5));
PI.assign(24,vector<ll>(n+6,-1));
for(int i=0; i<n; i++)
{
while(!q.empty()&&h[i]>h[q.top()])
{
PD[0][q.top()]=i;
q.pop();
}
if(!q.empty()) PI[0][i]=q.top();
q.push(i);
}
for(int i=1; i<24; i++)
for(int j=0; j<n+6; j++)
PD[i][j]=PD[i-1][PD[i-1][j]];
}
vector<ll> cache;
ll asd,asd2;
ll asdf;
ll sol(ll node)
{
if(node>asd2||node<0) return 1e9;
if(node>=asd) return 0;
if(cache[node]!=-1) return cache[node];
ll o1=(asdf>PI[0][node])+sol(PI[0][node]),o2=1+sol(PD[0][node]);
return cache[node]=min(o1,o2);
}
int minimum_jumps(int A, int B, int C, int D)
{
cache.assign(n+6,-1);
asd=C;
asd2=D;
asdf=A;
ll bs=sol(B);
if(bs>=1e9) bs=-1;
return bs;
}
# | 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... |