Submission #1236313

#TimeUsernameProblemLanguageResultExecution timeMemory
1236313AMel0nRainforest Jumps (APIO21_jumps)C++20
8 / 100
4042 ms25960 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define FOR(i,N) for(ll i = 0; i < N; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second

#include "jumps.h"
int N;
vector<int> H;
vector<vector<int>> g;

void init(int N, std::vector<int> H) {
    ::N = N;
    ::H = H;
    g.resize(N);

    FOR(x, N) {
        for(int y = x-1; y >= 0; y--) {
            if (H[y] > H[x]) {
                g[x].push_back(y);
                break;
            }
        }
        for(int y = x+1; y < N; y++) {
            if (H[y] > H[x]) {
                g[x].push_back(y);
                break;
            }
        }
    }

    // Subtask 4: binary search + segtree query(0, m) & query(m, N-1) 
    // FOR(i, N) {
    //     int l = 0, r = i;
    //     while(l < r) {}
    // }
}

int minimum_jumps(int A, int B, int C, int D) {
    int res = 1e9;

    priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>> > pq;
    for(int i = A; i <= B; i++) pq.push({0, i});
    vector<int> vis(N, 1e9);

    while(pq.size()) {
        int d = pq.top().F;
        int u = pq.top().S;
        pq.pop();

        if (vis[u] < d) continue;
        vis[u] = d;

        if (C <= u && u <= D) {
            res = min(res, d);
            continue;
        }

        for(int v: g[u]) {
            pq.push({d+1, v});
        }
    }

    return (res == 1e9) ? -1 : res;
}
#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...