Submission #478172

# Submission time Handle Problem Language Result Execution time Memory
478172 2021-10-06T07:41:37 Z khoabright Rainforest Jumps (APIO21_jumps) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define rep1(i, a, b) for (int i = (int)a; i >= (int)b; --i)
#define mp make_pair

const int N = 2e5 + 5;

int L[N], R[N], h[N];
int n;

void cal_LR() {
    rep(i, 1, n) {
        rep1(j, i - 1, 1) if (h[j] > h[i]) {
            L[i] = j;
            break;
        } 
        rep(j, i + 1, n) if (h[j] > h[i]) {
            R[i] = j;
            break;
        }
    }
}

int minimum_jumps(int a, int b, int c, int d) {
    queue<pii> q;
    vector<bool> vst(n + 1);
    vst[0] = 1;

    rep(i, a, b) q.push({i, 0}), vst[i] = 1;

    while (!q.empty()) {
        auto [u, w] = q.front();
        q.pop();
        if (c <= u && u <= d) return w;
        int v = L[u];
        if (!vst[v]) {
            q.push({v, w + 1});
            vst[v] = 1;
        }
        v = R[u];
        if (!vst[v]) {
            q.push({v, w + 1});
            vst[v] = 1;
        }
    }

    return -1;
}

void init(int sz, int array[]) {
    n = sz;
    rep(i, 1, n) h[i] = array[i - 1];   
    cal_LR();
}

Compilation message

/usr/bin/ld: /tmp/cc7RaiTD.o: in function `main':
stub.cpp:(.text.startup+0x177): undefined reference to `init(int, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status