Submission #1223353

#TimeUsernameProblemLanguageResultExecution timeMemory
1223353KALARRYRainforest Jumps (APIO21_jumps)C++20
4 / 100
279 ms5036 KiB
//chockolateman

#include<bits/stdc++.h>

using namespace std;


int n,l[200005],r[200005],dist[200005];
bool used[200005];

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

void BFS(int start)
{
    memset(used,false,sizeof(used));
    queue<int> q;
    used[start] = true;
    dist[start] = 0;
    q.push(start);
    while(!q.empty())
    {
        int v = q.front();
        q.pop();
        for(int u,k = 0 ; k <= 1 ; k++)
        {
            if(k==0)
                u = l[v];
            else
                u = r[v];
            if(1 <= u && u <= n && !used[u])
            {
                used[u] = true;
                dist[u] = dist[v] + 1;
                q.push(u);
            }
        }
    }
}

int minimum_jumps(int A, int B, int C, int D) {
    return C - B;
    int ret = 1e9;
    for(int v = A+1 ; v <= B+1 ; v++)
    {
        BFS(v);
        for(int u = C+1 ; u <= D+1 ; u++)
            if(used[u])
                ret = min(ret,dist[u]);
    }
    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...