Submission #1223466

#TimeUsernameProblemLanguageResultExecution timeMemory
1223466KALARRY밀림 점프 (APIO21_jumps)C++20
8 / 100
4085 ms5036 KiB
//chockolateman

#include<bits/stdc++.h>

using namespace std;


int n,l[200005],r[200005],a[200005];

void init(int N, std::vector<int> H) {
    for(int i = 1 ; i <= N ; i++)
        a[i] = H[i-1];
    n = N;
    stack<int> order;
    order.push(N+1);
    for(int i = 1 ; i <= N ; i++)
    {
        while(H[i-1] > order.top())
            order.pop();
        l[a[i]] = order.top();
        order.push(a[i]);
    }
    while(!order.empty())
        order.pop();
    order.push(N+1);
    for(int i = N ; i >= 1 ; i--)
    {
        while(H[i-1] > order.top())
            order.pop();
        r[a[i]] = order.top();
        order.push(a[i]);
    }
}


int ans(long long v,long long targ)
{
    if(v==targ)
        return 0;
    if(min(l[v],r[v]) > targ)
        return 1e9;
    long long res;
    if(max(l[v],r[v]) <= targ)
        res = ans(max(l[v],r[v]),targ) + 1;
    else
        res = ans(min(l[v],r[v]),targ) + 1;
    return res;
}

int minimum_jumps(int A, int B, int C, int D) {
    A++;
    B++;
    C++;
    D++;
    int ret = 1e9;
    for(int i = A ; i <= B ; i++)
        for(int j = C ; j <= D ; j++)
        {
            ret = min(ret,ans(a[i],a[j]));
        }
            if(ret > n)
        ret = -1;
    return ret;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...