Submission #1035842

# Submission time Handle Problem Language Result Execution time Memory
1035842 2024-07-26T16:42:03 Z _8_8_ Rainforest Jumps (APIO21_jumps) C++17
21 / 100
4000 ms 90460 KB
#include "jumps.h"
 
#include <vector>
#include <bits/stdc++.h>
using namespace std;
 
const int B = 20;
int n;
vector<vector<int>> build(vector<vector<int>> g,vector<int>rt){
    vector<vector<int>> up(n+1);
    function<void(int,int )> dfs = [&](int v,int pr) {
        up[v].resize(B);
        up[v][0] = pr;
        for(int i = 1;i < B;i++){
            up[v][i] = up[up[v][i - 1]][i - 1];
        }
        for(int to:g[v]) {  
            dfs(to,v);
        }
    };
    for(int i:rt) {
        dfs(i,i);
    }
    return up;
}
vector<vector<int>> up,up1;
const int maxn = (int)2e5 + 12;
int l[maxn],r[maxn];
vector<int> h;
void init(int N, vector<int> H) {
    h = H;
    n = N;
    vector<int> st,rt;
    vector<vector<int>> G(n);
    for(int i = 0;i < N;i++) {
        while(!(int)st.empty() && H[st.back()] < H[i]) {
            st.pop_back();
        }
        if(st.empty()){
            rt.push_back(i);
            l[i] = -1;
        }else {
            G[st.back()].push_back(i);            
            l[i] = st.back();
        }
        st.push_back(i);
    }
    up = build(G,rt);
    for(int i = 0;i < n;i++){
        G[i].clear();
    }
    rt.clear();
    st.clear();
    for(int i = N - 1;i >= 0;i--){
        while(!st.empty() && H[st.back()] < H[i]){
            st.pop_back();
        }
        if(st.empty()){
            rt.push_back(i);
            r[i] = -1;
        }else {
            G[st.back()].push_back(i);
            r[i] = st.back();
        }
        st.push_back(i);
    }
    up1 = build(G,rt);
}
bool check(int ver,int C,int D){
    for(int i = B - 1;i >= 0;i--){
        if(up1[ver][i] < C){
            ver = up1[ver][i];
        }
    }
    ver = up1[ver][0];
    return (ver >= C && ver <= D);
}
int go(int ver,int C,int D) {
    if(ver >= C && ver <= D) return 0;
    if(r[ver] >= C && r[ver] <= D) return 1;

    if(l[ver] == -1 || h[r[ver]] > h[l[ver]] || !check(l[ver],C,D)){
        return go(r[ver],C,D) + 1;
    }
    return go(l[ver],C,D) + 1;
}
int minimum_jumps(int A, int B, int C, int D) {
    if(!check(B,C,D)) return -1;
    int res = 1e9;
    for(int i = A;i <= B;i++) {
        if(check(i,C,D)){
            res = min(res,go(i,C,D));
        }
    }
    // int ver = B;
    // for(int i = 19;i >= 0;i--){
    //     if(up[ver][i] >= A && check(ver,C,D) != -1){
    //         ver = up[ver][i];
    //     }
    // }
    if(res == 1e9) res = -1;
    return res;
    // if(!check(ver,C,D)){
    //     return -1;
    // }
    // return go(ver,C,D);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Execution timed out 4065 ms 71848 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 3 ms 344 KB Output is correct
12 Correct 3 ms 344 KB Output is correct
13 Correct 3 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 6 ms 344 KB Output is correct
16 Correct 3 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 3 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 5 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 3 ms 344 KB Output is correct
12 Correct 3 ms 344 KB Output is correct
13 Correct 3 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 6 ms 344 KB Output is correct
16 Correct 3 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 3 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 5 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 2 ms 344 KB Output is correct
45 Correct 2 ms 344 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 1 ms 344 KB Output is correct
48 Correct 1 ms 344 KB Output is correct
49 Correct 2 ms 344 KB Output is correct
50 Correct 3 ms 344 KB Output is correct
51 Correct 3 ms 344 KB Output is correct
52 Correct 3 ms 344 KB Output is correct
53 Correct 1 ms 344 KB Output is correct
54 Correct 4 ms 344 KB Output is correct
55 Correct 2 ms 344 KB Output is correct
56 Correct 1 ms 344 KB Output is correct
57 Correct 0 ms 344 KB Output is correct
58 Correct 35 ms 856 KB Output is correct
59 Correct 37 ms 1112 KB Output is correct
60 Correct 7 ms 600 KB Output is correct
61 Correct 38 ms 1112 KB Output is correct
62 Correct 8 ms 344 KB Output is correct
63 Correct 40 ms 1112 KB Output is correct
64 Correct 1634 ms 1112 KB Output is correct
65 Correct 1610 ms 1112 KB Output is correct
66 Correct 1079 ms 1112 KB Output is correct
67 Correct 23 ms 1112 KB Output is correct
68 Correct 2393 ms 1112 KB Output is correct
69 Correct 117 ms 1112 KB Output is correct
70 Correct 60 ms 1112 KB Output is correct
71 Correct 1 ms 344 KB Output is correct
72 Correct 0 ms 344 KB Output is correct
73 Correct 1 ms 344 KB Output is correct
74 Correct 3 ms 344 KB Output is correct
75 Correct 1 ms 344 KB Output is correct
76 Correct 6 ms 344 KB Output is correct
77 Correct 1 ms 344 KB Output is correct
78 Correct 0 ms 344 KB Output is correct
79 Correct 0 ms 344 KB Output is correct
80 Correct 1 ms 344 KB Output is correct
81 Correct 1 ms 344 KB Output is correct
82 Correct 1 ms 344 KB Output is correct
83 Correct 1 ms 344 KB Output is correct
84 Correct 2 ms 344 KB Output is correct
85 Correct 1 ms 344 KB Output is correct
86 Correct 0 ms 344 KB Output is correct
87 Correct 0 ms 344 KB Output is correct
88 Correct 0 ms 344 KB Output is correct
89 Correct 0 ms 344 KB Output is correct
90 Correct 1 ms 344 KB Output is correct
91 Correct 0 ms 344 KB Output is correct
92 Correct 0 ms 344 KB Output is correct
93 Correct 0 ms 344 KB Output is correct
94 Correct 3 ms 344 KB Output is correct
95 Correct 12 ms 1112 KB Output is correct
96 Correct 1439 ms 1124 KB Output is correct
97 Correct 9 ms 1112 KB Output is correct
98 Correct 2460 ms 1112 KB Output is correct
99 Correct 25 ms 1112 KB Output is correct
100 Correct 0 ms 344 KB Output is correct
101 Correct 1 ms 600 KB Output is correct
102 Correct 11 ms 1112 KB Output is correct
103 Correct 13 ms 1112 KB Output is correct
104 Correct 10 ms 1112 KB Output is correct
105 Correct 14 ms 1112 KB Output is correct
106 Correct 10 ms 1112 KB Output is correct
107 Correct 0 ms 344 KB Output is correct
108 Correct 1 ms 600 KB Output is correct
109 Correct 1 ms 1112 KB Output is correct
110 Correct 5 ms 1112 KB Output is correct
111 Correct 2 ms 1112 KB Output is correct
112 Correct 5 ms 1112 KB Output is correct
113 Correct 1 ms 1112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 96 ms 54916 KB Output is correct
6 Correct 111 ms 68092 KB Output is correct
7 Correct 55 ms 35056 KB Output is correct
8 Correct 139 ms 68348 KB Output is correct
9 Correct 18 ms 10636 KB Output is correct
10 Correct 121 ms 68092 KB Output is correct
11 Execution timed out 4009 ms 90460 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 213 ms 31412 KB Output is correct
5 Correct 767 ms 68096 KB Output is correct
6 Correct 459 ms 11600 KB Output is correct
7 Correct 773 ms 68076 KB Output is correct
8 Correct 414 ms 23552 KB Output is correct
9 Correct 748 ms 68092 KB Output is correct
10 Execution timed out 4019 ms 90324 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 213 ms 31412 KB Output is correct
5 Correct 767 ms 68096 KB Output is correct
6 Correct 459 ms 11600 KB Output is correct
7 Correct 773 ms 68076 KB Output is correct
8 Correct 414 ms 23552 KB Output is correct
9 Correct 748 ms 68092 KB Output is correct
10 Execution timed out 4019 ms 90324 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Execution timed out 4065 ms 71848 KB Time limit exceeded
4 Halted 0 ms 0 KB -