Submission #478185

# Submission time Handle Problem Language Result Execution time Memory
478185 2021-10-06T09:40:49 Z khoabright Rainforest Jumps (APIO21_jumps) C++17
25 / 100
4000 ms 5016 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 my_size;
bool sub1 = 1;

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



int minimum_jumps(int a, int b, int c, int d) {
    if (sub1) return c - b;
    ++a, ++b, ++c, ++d;
    queue<pii> q;
    vector<bool> vst(my_size + 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, vector<int> array) {
    my_size = sz;
    rep(i, 1, my_size) h[i] = array[i - 1];   
    cal_LR();
}

// int main() {
//     ios_base::sync_with_stdio(0);
//     cin.tie(0); cout.tie(0);

//     // int x; cin >> x;
//     // int array[10];
//     // rep(i, 1, x) cin >> array[i - 1];
//     // init(x,array);
    
//     // rep(i, 1, my_size) cout << h[i] << ' ';
//     // cout << '\my_size';
//     // rep(i, 1, my_size) cout << L[i] << ' ' << R[i]<< '\my_size';

//     // int q; cin >> q;
//     // while (q--) {
//     //     int A, B, C, D;
//     //     cin >> A >> B >> C >> D;
//     //     cout << minimum_jumps(A + 1, B + 1, C + 1, D + 1) << '\my_size';
//     // }
// }
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 129 ms 2072 KB Output is correct
4 Correct 988 ms 2592 KB Output is correct
5 Correct 885 ms 1472 KB Output is correct
6 Correct 1157 ms 2624 KB Output is correct
7 Correct 800 ms 1864 KB Output is correct
8 Correct 1012 ms 2612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 0 ms 200 KB Output is correct
5 Correct 2 ms 200 KB Output is correct
6 Correct 3 ms 200 KB Output is correct
7 Correct 3 ms 200 KB Output is correct
8 Correct 3 ms 200 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 2 ms 200 KB Output is correct
11 Correct 2 ms 200 KB Output is correct
12 Correct 2 ms 200 KB Output is correct
13 Correct 3 ms 200 KB Output is correct
14 Correct 3 ms 200 KB Output is correct
15 Correct 3 ms 200 KB Output is correct
16 Correct 2 ms 200 KB Output is correct
17 Correct 3 ms 200 KB Output is correct
18 Correct 0 ms 200 KB Output is correct
19 Correct 1 ms 200 KB Output is correct
20 Correct 4 ms 200 KB Output is correct
21 Correct 3 ms 200 KB Output is correct
22 Correct 2 ms 200 KB Output is correct
23 Correct 4 ms 200 KB Output is correct
24 Correct 3 ms 200 KB Output is correct
25 Correct 0 ms 200 KB Output is correct
26 Correct 0 ms 200 KB Output is correct
27 Correct 3 ms 200 KB Output is correct
28 Correct 3 ms 200 KB Output is correct
29 Correct 3 ms 200 KB Output is correct
30 Correct 2 ms 200 KB Output is correct
31 Correct 4 ms 200 KB Output is correct
32 Correct 2 ms 200 KB Output is correct
33 Correct 0 ms 200 KB Output is correct
34 Correct 1 ms 200 KB Output is correct
35 Correct 0 ms 200 KB Output is correct
36 Correct 1 ms 200 KB Output is correct
37 Correct 1 ms 200 KB Output is correct
38 Correct 1 ms 200 KB Output is correct
39 Correct 0 ms 200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 0 ms 200 KB Output is correct
5 Correct 2 ms 200 KB Output is correct
6 Correct 3 ms 200 KB Output is correct
7 Correct 3 ms 200 KB Output is correct
8 Correct 3 ms 200 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 2 ms 200 KB Output is correct
11 Correct 2 ms 200 KB Output is correct
12 Correct 2 ms 200 KB Output is correct
13 Correct 3 ms 200 KB Output is correct
14 Correct 3 ms 200 KB Output is correct
15 Correct 3 ms 200 KB Output is correct
16 Correct 2 ms 200 KB Output is correct
17 Correct 3 ms 200 KB Output is correct
18 Correct 0 ms 200 KB Output is correct
19 Correct 1 ms 200 KB Output is correct
20 Correct 4 ms 200 KB Output is correct
21 Correct 3 ms 200 KB Output is correct
22 Correct 2 ms 200 KB Output is correct
23 Correct 4 ms 200 KB Output is correct
24 Correct 3 ms 200 KB Output is correct
25 Correct 0 ms 200 KB Output is correct
26 Correct 0 ms 200 KB Output is correct
27 Correct 3 ms 200 KB Output is correct
28 Correct 3 ms 200 KB Output is correct
29 Correct 3 ms 200 KB Output is correct
30 Correct 2 ms 200 KB Output is correct
31 Correct 4 ms 200 KB Output is correct
32 Correct 2 ms 200 KB Output is correct
33 Correct 0 ms 200 KB Output is correct
34 Correct 1 ms 200 KB Output is correct
35 Correct 0 ms 200 KB Output is correct
36 Correct 1 ms 200 KB Output is correct
37 Correct 1 ms 200 KB Output is correct
38 Correct 1 ms 200 KB Output is correct
39 Correct 0 ms 200 KB Output is correct
40 Correct 1 ms 200 KB Output is correct
41 Correct 0 ms 200 KB Output is correct
42 Correct 1 ms 200 KB Output is correct
43 Correct 0 ms 200 KB Output is correct
44 Correct 3 ms 200 KB Output is correct
45 Correct 2 ms 200 KB Output is correct
46 Correct 2 ms 200 KB Output is correct
47 Correct 3 ms 200 KB Output is correct
48 Correct 1 ms 200 KB Output is correct
49 Correct 3 ms 200 KB Output is correct
50 Correct 2 ms 200 KB Output is correct
51 Correct 3 ms 200 KB Output is correct
52 Correct 5 ms 200 KB Output is correct
53 Correct 3 ms 200 KB Output is correct
54 Correct 3 ms 200 KB Output is correct
55 Correct 3 ms 200 KB Output is correct
56 Correct 2 ms 200 KB Output is correct
57 Correct 0 ms 200 KB Output is correct
58 Correct 29 ms 328 KB Output is correct
59 Correct 40 ms 328 KB Output is correct
60 Correct 9 ms 328 KB Output is correct
61 Correct 43 ms 348 KB Output is correct
62 Correct 22 ms 200 KB Output is correct
63 Correct 41 ms 348 KB Output is correct
64 Correct 23 ms 200 KB Output is correct
65 Correct 60 ms 328 KB Output is correct
66 Correct 52 ms 328 KB Output is correct
67 Correct 38 ms 328 KB Output is correct
68 Correct 52 ms 328 KB Output is correct
69 Correct 49 ms 328 KB Output is correct
70 Correct 36 ms 332 KB Output is correct
71 Correct 0 ms 208 KB Output is correct
72 Correct 1 ms 200 KB Output is correct
73 Correct 3 ms 200 KB Output is correct
74 Correct 3 ms 200 KB Output is correct
75 Correct 5 ms 200 KB Output is correct
76 Correct 4 ms 200 KB Output is correct
77 Correct 3 ms 200 KB Output is correct
78 Correct 0 ms 200 KB Output is correct
79 Correct 0 ms 200 KB Output is correct
80 Correct 2 ms 200 KB Output is correct
81 Correct 3 ms 200 KB Output is correct
82 Correct 3 ms 200 KB Output is correct
83 Correct 3 ms 200 KB Output is correct
84 Correct 3 ms 200 KB Output is correct
85 Correct 4 ms 200 KB Output is correct
86 Correct 0 ms 200 KB Output is correct
87 Correct 0 ms 200 KB Output is correct
88 Correct 1 ms 200 KB Output is correct
89 Correct 1 ms 200 KB Output is correct
90 Correct 1 ms 200 KB Output is correct
91 Correct 0 ms 200 KB Output is correct
92 Correct 0 ms 200 KB Output is correct
93 Correct 0 ms 200 KB Output is correct
94 Correct 4 ms 200 KB Output is correct
95 Correct 37 ms 344 KB Output is correct
96 Correct 57 ms 328 KB Output is correct
97 Correct 41 ms 328 KB Output is correct
98 Correct 45 ms 328 KB Output is correct
99 Correct 51 ms 328 KB Output is correct
100 Correct 0 ms 200 KB Output is correct
101 Correct 1 ms 200 KB Output is correct
102 Correct 18 ms 328 KB Output is correct
103 Correct 46 ms 328 KB Output is correct
104 Correct 17 ms 328 KB Output is correct
105 Correct 32 ms 328 KB Output is correct
106 Correct 42 ms 328 KB Output is correct
107 Correct 0 ms 200 KB Output is correct
108 Correct 1 ms 200 KB Output is correct
109 Correct 1 ms 328 KB Output is correct
110 Correct 2 ms 328 KB Output is correct
111 Correct 1 ms 328 KB Output is correct
112 Correct 2 ms 328 KB Output is correct
113 Correct 2 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 0 ms 200 KB Output is correct
5 Correct 34 ms 3484 KB Output is correct
6 Correct 33 ms 4116 KB Output is correct
7 Correct 13 ms 2236 KB Output is correct
8 Correct 31 ms 5016 KB Output is correct
9 Correct 5 ms 896 KB Output is correct
10 Correct 31 ms 4160 KB Output is correct
11 Correct 23 ms 2588 KB Output is correct
12 Execution timed out 4014 ms 3864 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 324 ms 2080 KB Output is correct
5 Correct 989 ms 4124 KB Output is correct
6 Correct 725 ms 840 KB Output is correct
7 Correct 1027 ms 4160 KB Output is correct
8 Correct 730 ms 1608 KB Output is correct
9 Correct 1203 ms 4160 KB Output is correct
10 Correct 998 ms 2604 KB Output is correct
11 Execution timed out 4034 ms 3744 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 324 ms 2080 KB Output is correct
5 Correct 989 ms 4124 KB Output is correct
6 Correct 725 ms 840 KB Output is correct
7 Correct 1027 ms 4160 KB Output is correct
8 Correct 730 ms 1608 KB Output is correct
9 Correct 1203 ms 4160 KB Output is correct
10 Correct 998 ms 2604 KB Output is correct
11 Execution timed out 4034 ms 3744 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 129 ms 2072 KB Output is correct
4 Correct 988 ms 2592 KB Output is correct
5 Correct 885 ms 1472 KB Output is correct
6 Correct 1157 ms 2624 KB Output is correct
7 Correct 800 ms 1864 KB Output is correct
8 Correct 1012 ms 2612 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 0 ms 200 KB Output is correct
11 Correct 0 ms 200 KB Output is correct
12 Correct 0 ms 200 KB Output is correct
13 Correct 2 ms 200 KB Output is correct
14 Correct 3 ms 200 KB Output is correct
15 Correct 3 ms 200 KB Output is correct
16 Correct 3 ms 200 KB Output is correct
17 Correct 1 ms 200 KB Output is correct
18 Correct 2 ms 200 KB Output is correct
19 Correct 2 ms 200 KB Output is correct
20 Correct 2 ms 200 KB Output is correct
21 Correct 3 ms 200 KB Output is correct
22 Correct 3 ms 200 KB Output is correct
23 Correct 3 ms 200 KB Output is correct
24 Correct 2 ms 200 KB Output is correct
25 Correct 3 ms 200 KB Output is correct
26 Correct 0 ms 200 KB Output is correct
27 Correct 1 ms 200 KB Output is correct
28 Correct 4 ms 200 KB Output is correct
29 Correct 3 ms 200 KB Output is correct
30 Correct 2 ms 200 KB Output is correct
31 Correct 4 ms 200 KB Output is correct
32 Correct 3 ms 200 KB Output is correct
33 Correct 0 ms 200 KB Output is correct
34 Correct 0 ms 200 KB Output is correct
35 Correct 3 ms 200 KB Output is correct
36 Correct 3 ms 200 KB Output is correct
37 Correct 3 ms 200 KB Output is correct
38 Correct 2 ms 200 KB Output is correct
39 Correct 4 ms 200 KB Output is correct
40 Correct 2 ms 200 KB Output is correct
41 Correct 0 ms 200 KB Output is correct
42 Correct 1 ms 200 KB Output is correct
43 Correct 0 ms 200 KB Output is correct
44 Correct 1 ms 200 KB Output is correct
45 Correct 1 ms 200 KB Output is correct
46 Correct 1 ms 200 KB Output is correct
47 Correct 0 ms 200 KB Output is correct
48 Correct 1 ms 200 KB Output is correct
49 Correct 0 ms 200 KB Output is correct
50 Correct 1 ms 200 KB Output is correct
51 Correct 0 ms 200 KB Output is correct
52 Correct 3 ms 200 KB Output is correct
53 Correct 2 ms 200 KB Output is correct
54 Correct 2 ms 200 KB Output is correct
55 Correct 3 ms 200 KB Output is correct
56 Correct 1 ms 200 KB Output is correct
57 Correct 3 ms 200 KB Output is correct
58 Correct 2 ms 200 KB Output is correct
59 Correct 3 ms 200 KB Output is correct
60 Correct 5 ms 200 KB Output is correct
61 Correct 3 ms 200 KB Output is correct
62 Correct 3 ms 200 KB Output is correct
63 Correct 3 ms 200 KB Output is correct
64 Correct 2 ms 200 KB Output is correct
65 Correct 0 ms 200 KB Output is correct
66 Correct 29 ms 328 KB Output is correct
67 Correct 40 ms 328 KB Output is correct
68 Correct 9 ms 328 KB Output is correct
69 Correct 43 ms 348 KB Output is correct
70 Correct 22 ms 200 KB Output is correct
71 Correct 41 ms 348 KB Output is correct
72 Correct 23 ms 200 KB Output is correct
73 Correct 60 ms 328 KB Output is correct
74 Correct 52 ms 328 KB Output is correct
75 Correct 38 ms 328 KB Output is correct
76 Correct 52 ms 328 KB Output is correct
77 Correct 49 ms 328 KB Output is correct
78 Correct 36 ms 332 KB Output is correct
79 Correct 0 ms 208 KB Output is correct
80 Correct 1 ms 200 KB Output is correct
81 Correct 3 ms 200 KB Output is correct
82 Correct 3 ms 200 KB Output is correct
83 Correct 5 ms 200 KB Output is correct
84 Correct 4 ms 200 KB Output is correct
85 Correct 3 ms 200 KB Output is correct
86 Correct 0 ms 200 KB Output is correct
87 Correct 0 ms 200 KB Output is correct
88 Correct 2 ms 200 KB Output is correct
89 Correct 3 ms 200 KB Output is correct
90 Correct 3 ms 200 KB Output is correct
91 Correct 3 ms 200 KB Output is correct
92 Correct 3 ms 200 KB Output is correct
93 Correct 4 ms 200 KB Output is correct
94 Correct 0 ms 200 KB Output is correct
95 Correct 0 ms 200 KB Output is correct
96 Correct 1 ms 200 KB Output is correct
97 Correct 1 ms 200 KB Output is correct
98 Correct 1 ms 200 KB Output is correct
99 Correct 0 ms 200 KB Output is correct
100 Correct 0 ms 200 KB Output is correct
101 Correct 0 ms 200 KB Output is correct
102 Correct 4 ms 200 KB Output is correct
103 Correct 37 ms 344 KB Output is correct
104 Correct 57 ms 328 KB Output is correct
105 Correct 41 ms 328 KB Output is correct
106 Correct 45 ms 328 KB Output is correct
107 Correct 51 ms 328 KB Output is correct
108 Correct 0 ms 200 KB Output is correct
109 Correct 1 ms 200 KB Output is correct
110 Correct 18 ms 328 KB Output is correct
111 Correct 46 ms 328 KB Output is correct
112 Correct 17 ms 328 KB Output is correct
113 Correct 32 ms 328 KB Output is correct
114 Correct 42 ms 328 KB Output is correct
115 Correct 0 ms 200 KB Output is correct
116 Correct 1 ms 200 KB Output is correct
117 Correct 1 ms 328 KB Output is correct
118 Correct 2 ms 328 KB Output is correct
119 Correct 1 ms 328 KB Output is correct
120 Correct 2 ms 328 KB Output is correct
121 Correct 2 ms 328 KB Output is correct
122 Correct 0 ms 200 KB Output is correct
123 Correct 0 ms 200 KB Output is correct
124 Correct 0 ms 200 KB Output is correct
125 Correct 0 ms 200 KB Output is correct
126 Correct 34 ms 3484 KB Output is correct
127 Correct 33 ms 4116 KB Output is correct
128 Correct 13 ms 2236 KB Output is correct
129 Correct 31 ms 5016 KB Output is correct
130 Correct 5 ms 896 KB Output is correct
131 Correct 31 ms 4160 KB Output is correct
132 Correct 23 ms 2588 KB Output is correct
133 Execution timed out 4014 ms 3864 KB Time limit exceeded
134 Halted 0 ms 0 KB -