Submission #558755

# Submission time Handle Problem Language Result Execution time Memory
558755 2022-05-08T09:13:47 Z hoanghq2004 Rainforest Jumps (APIO21_jumps) C++14
0 / 100
1 ms 336 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "jumps.h"

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 2e5 + 10;

int n, h[N];
int high[N][20], low[N][20];
int L[N], R[N];
int nxt[N][20];

void init(int N, std::vector<int> H) {
    n = N;
    for (int i = 1; i <= n; ++i) h[i] = H[i - 1];
    stack <int> stk;
    for (int i = 1; i <= n; ++i) {
        while (stk.size() && h[stk.top()] < h[i]) {
            R[stk.top()] = i;
            stk.pop();
        }
        stk.push(i);
    }
    while (stk.size()) R[stk.top()] = n + 1, stk.pop();
    for (int i = n; i >= 1; --i) {
        while (stk.size() && h[stk.top()] < h[i]) {
            L[stk.top()] = i;
            stk.pop();
        }
        stk.push(i);
    }
    while (stk.size()) L[stk.top()] = 0, stk.pop();
    for (int i = 1; i <= n; ++i) {
        high[i][0] = (h[L[i]] > h[R[i]] ? L[i] : R[i]);
        low[i][0] = (h[L[i]] < h[R[i]] ? L[i] : R[i]);
        nxt[i][0] = R[i];
    }
    for (int lg = 1; (1 << lg) <= n; ++lg) {
        for (int i = 1; i + (1 << lg) - 1 <= n; ++i) {
            high[i][lg] = high[high[i][lg - 1]][lg - 1];
            low[i][lg] = low[low[i][lg - 1]][lg - 1];
            nxt[i][lg] = nxt[nxt[i][lg - 1]][lg - 1];
        }
    }
}

int minimum_jumps(int A, int B, int C, int D) {
    ++A, ++B, ++C, ++D;
    for (int lg = 19; lg >= 0; --lg)
        if (nxt[A][lg] <= B && h[nxt[A][lg]] <= h[C]) A = nxt[A][lg];
    int cost = 0;
    for (int lg = 19; lg >= 0; --lg)
        if (h[high[A][lg]] && h[high[A][lg]] <= h[C])
            A = high[A][lg],
            cost += (1 << lg);
    for (int lg = 19; lg >= 0; --lg)
        if (h[low[A][lg]] && h[low[A][lg]] <= h[C])
            A = low[A][lg],
            cost += (1 << lg);
    if (A != C) return -1;
    return cost;
}

//int main() {
//  int N, Q;
//  assert(2 == scanf("%d %d", &N, &Q));
//  std::vector<int> H(N);
//  for (int i = 0; i < N; ++i) {
//    assert(1 == scanf("%d", &H[i]));
//  }
//  init(N, H);
//
//  for (int i = 0; i < Q; ++i) {
//    int A, B, C, D;
//    assert(4 == scanf("%d %d %d %d", &A, &B, &C, &D));
//    printf("%d\n", minimum_jumps(A, B, C, D));
//  }
//  return 0;
//}

# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -