제출 #617984

#제출 시각아이디문제언어결과실행 시간메모리
617984AmirElarbiRainforest Jumps (APIO21_jumps)C++14
0 / 100
4051 ms51260 KiB
#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 2e9+5
#define eps 1e-7
#define eps1 1e-25
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 1e5+5
#define V 450
using namespace std;
const int MOD = 1e9;
const int nax = 4e5+5;
const int lg = 30;
int nxt[nax][lg], mx[nax],bst[nax][lg];
void init(int n, vi h) {
    stack<ii> st;
    for (int i = n-1; i >= 0; --i)
    {
        while(!st.empty() && st.top().fi <= h[i]){
            st.pop();
        }
        if(st.empty()) bst[i][0] = nxt[i][0] = INF; 
        else bst[i][0] = nxt[i][0] = st.top().se, mx[i] = st.top().fi;
        st.push({h[i], i});
    }
    for (int i = 0; i < n-1; ++i)
    {
        while(!st.empty() && st.top().fi <= h[i]){
            st.pop();
        }
        if(!st.empty() && mx[i] < st.top().fi) bst[i][0] = st.top().se;
        st.push({h[i], i});
    }
    for (int i = 1; i < lg; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if(nxt[j][i-1] == INF) nxt[j][i] = INF;
            else nxt[j][i] = nxt[nxt[j][i-1]][i-1];
            if(bst[j][i-1] == INF) bst[j][i] = INF;
            else bst[j][i] = bst[bst[j][i-1]][i-1];
        }
    }
}

int minimum_jumps(int a, int b, int c, int d) {
    int mn = INF;
    for (int i = a; i <= b; ++i)
    {
        int cur = i, res = 0;
        for (int j = lg-1; j >= 0; --j)
        {
            if(bst[cur][j] < c && nxt[cur][0] < c){
                cur = bst[cur][j];
                res += (1 << j);
            }
        }
        if(nxt[cur][0] <= d){
            mn = min(mn, res+1);
        } 
    }
    if(mn == INF) return -1;
    return mn;
}
    
#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...