Submission #671324

# Submission time Handle Problem Language Result Execution time Memory
671324 2022-12-12T20:38:34 Z YENGOYAN Rainforest Jumps (APIO21_jumps) C++17
0 / 100
0 ms 208 KB
#include "jumps.h"
#include <bits/stdc++.h>

using namespace std;

vector<int> l, r, h;
bool f = 1;
int n;

void calcDp(int u, vector<int> &dp, int c, int d){
    if(dp[u] != -1) return;
    if(u >= c && u <= d) {
        dp[u] = 0;
        return;
    }
    if(l[u] != -1 && r[u] != -1) {
        calcDp(l[u], dp, c, d);
        calcDp(r[u], dp, c, d);
        dp[u] = min(dp[l[u]], dp[r[u]]) + 1;
    }
    else if(l[u] != -1) {
        calcDp(l[u], dp, c, d);
        dp[u] = dp[l[u]] + 1;
    }
    else if(r[u] != -1){
        calcDp(r[u], dp, c, d);
        dp[u] = dp[r[u]] + 1;
    }
    else dp[u] = 1e9;
}


bool check(int n, int q){
    if(n <= 2000 && q <= 2000) return 1;
    if(q <= 5) return 1;
    return 1;
}

void init(int N, vector<int> H) {
    n = N, h = H;
    l = r = vector<int> (n, -1);
    stack<pair<int, int>> st;
    st.push({1e9, -1});
    for(int i = n - 1; i >= 0; i--){
        while(st.top().first < h[i]){
            st.pop();
        }
        r[i] = st.top().second;
        st.push({h[i], i});
    }
    while(st.size())st.pop();
    st.push({1e9, 1});
    for(int i = 0; i < n; i++){
        while(st.top().first < h[i]){
            st.pop();
        }
        l[i] = st.top().second;
        st.push({h[i], i});
    }
    int q; cin >> q;
    for(int i = 0; i < n; i++) if(h[i] != i + 1) f = 0;
}

int minimum_jumps(int A, int B, int C, int D) {
    if(f) return C - B;
    vector<int> dp(n, -1);
    for(int i = A; i < B; i++) calcDp(i, dp, C, D);
    int ans = 2e9;
    for(int i = A; i < B; i++){
        ans = min(ans, dp[i]);
    }
    if(ans >= 1e9) return -1;
    return ans;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 0 ms 208 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 0 ms 208 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 0 ms 208 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 0 ms 208 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 0 ms 208 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 0 ms 208 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 0 ms 208 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -