Submission #426110

# Submission time Handle Problem Language Result Execution time Memory
426110 2021-06-13T14:15:29 Z ocarima Rainforest Jumps (APIO21_jumps) C++14
0 / 100
266 ms 48452 KB
#include "jumps.h"
#include <vector>
#include<bits/stdc++.h>

using namespace std;

#define lli long long
#define rep(i, a, b) for(lli i = (a); i <= (b); ++i)
#define repa(i, a, b) for(lli i = (a); i >= (b); --i)

#define nl "\n"
#define debugsl(x) cout << #x << " = " << x << ", "
#define debug(x) debugsl(x) << nl
#define debugarr(x, a, b) cout << #x << " = ["; rep(ii, a, b){ cout << x[ii] << ", "; } cout << "]" << nl

#define MAX_N 200003
#define LOG_N 17

int maximo[LOG_N][MAX_N], minimo[LOG_N][MAX_N], n, pot[MAX_N];
int izq[MAX_N], der[MAX_N];
int k, res;

int maxrango(int l, int r){
    k = pot[r - l + 1];
    return max(maximo[k][l], maximo[k][r - (1 << k) + 1]);
}

int minrango(int l, int r){
    k = pot[r - l + 1];
    return min(minimo[k][l], minimo[k][r - (1 << k) + 1]);
}

void init(int N, std::vector<int> H) {
    int p = 1, k = 0;
    n = N;
    rep(i, 0, n - 1) maximo[0][i + 1] = minimo[0][i + 1] = H[i];
    maximo[0][0] = maximo[0][n + 1] = minimo[0][0] = minimo[0][n + 1] = n + 1;

    rep(k, 1, LOG_N - 1){
        rep(i, 0, (n + 1) - p - p + 1){
            maximo[k][i] = max(maximo[k - 1][i], maximo[k - 1][i + p]);
            minimo[k][i] = min(minimo[k - 1][i], minimo[k - 1][i + p]);
        }
        p <<= 1;
    }

    p = 1;
    rep(i, 1, MAX_N - 1){
        pot[i] = k;
        if (p + p <= i){ p <<= 1; ++k; }
    }

    // OBTEN EL SIGUIENTE SALTO A LA DERECHA Y A LA IZQUIERDA DE CADA NUMERO
    int l, r, mitad, cur;
    rep(i, 1, n){
        // OBTEN SU SALTO A LA IZQUIERDA;
        l = 0;
        r = i - 1;
        cur = l;
        while (l <= r){
            mitad = (l + r) / 2;
            if (maxrango(mitad, i - 1) > H[i - 1]){
                l = mitad + 1;
                cur = mitad;
            }
            else r = mitad - 1;
        }
        izq[i] = cur;

        // OBTEN SU SALTO A LA DERECHA;
        l = i + 1;
        r = n + 1;
        cur = n + 1;
        while (l <= r){
            mitad = (l + r) / 2;
            if (maxrango(i + 1, mitad) > H[i - 1]){
                r = mitad - 1;
                cur = mitad;
            }
            else l = mitad + 1;
        }
        der[i] = cur;
    }
}

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

    ++A; ++B; ++C; ++D;

    int maxdestino;
    int cnt, pos;

    maxdestino = (maxrango(C, D));
    rep(i, A, B){
        pos = i;
        cnt = 0;
        while (pos != 0 && pos != n + 1){
            if (der[pos] >= C && der[pos] <= D) pos = der[pos];
            else if (izq[pos] < maxdestino && izq[pos] > der[pos]) pos = izq[pos];
            else if (der[pos] < maxdestino && der[pos] > izq[pos]) pos = der[pos];
            else{
                cnt = n + 1;
                break;
            }

            ++cnt;
            if (pos >= C && pos <= D){
                res = min(res, cnt);
                break;
            }
        }
    }

    return (res == n + 1) ? -1 : res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1096 KB Output is correct
2 Correct 1 ms 1096 KB Output is correct
3 Runtime error 83 ms 47764 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1096 KB Output is correct
2 Correct 1 ms 1096 KB Output is correct
3 Correct 1 ms 1096 KB Output is correct
4 Correct 1 ms 1096 KB Output is correct
5 Incorrect 3 ms 1096 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1096 KB Output is correct
2 Correct 1 ms 1096 KB Output is correct
3 Correct 1 ms 1096 KB Output is correct
4 Correct 1 ms 1096 KB Output is correct
5 Incorrect 3 ms 1096 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1096 KB Output is correct
2 Correct 1 ms 1096 KB Output is correct
3 Correct 1 ms 1096 KB Output is correct
4 Correct 1 ms 1096 KB Output is correct
5 Runtime error 85 ms 48452 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1096 KB Output is correct
2 Correct 1 ms 1096 KB Output is correct
3 Correct 1 ms 1096 KB Output is correct
4 Incorrect 266 ms 13780 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1096 KB Output is correct
2 Correct 1 ms 1096 KB Output is correct
3 Correct 1 ms 1096 KB Output is correct
4 Incorrect 266 ms 13780 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1096 KB Output is correct
2 Correct 1 ms 1096 KB Output is correct
3 Runtime error 83 ms 47764 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -