Submission #1047516

# Submission time Handle Problem Language Result Execution time Memory
1047516 2024-08-07T13:48:03 Z SN0WM4N Rainforest Jumps (APIO21_jumps) C++14
33 / 100
4000 ms 10620 KB
#include "jumps.h"

#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second 

vector<int> v;
vector<int> m_sig, m_prev;

class FT{
private:
        int n;
        vector<int> v;

public:
        FT(int _n) {
                n = _n;
                v.resize(n + 10);
        }

        void update(int p, int x) {
                p ++;
                while (p <= n) {
                        v[p] += x;
                        p += p & -p;
                }
        }

        int query(int p) {
                p ++;
                int res = 0;
                while (0 < p) {
                        res += v[p];
                        p -= p & -p;
                }
                return res;
        }

        int query(int l, int r) {
                return query(r) - query(l - 1);
        }
};

void init(int N, std::vector<int> H) {
        v = H;
        m_sig.resize(N);
        m_prev.resize(N);

        vector<pair<int, int>> pos(N);

        for (int i = 0; i < N; i ++) 
                pos[i] = {H[i], i}; 

        stable_sort(pos.rbegin(), pos.rend());

        for (int i = 0; i < N; i ++) 
                cerr << "{" << pos[i].F << " " << pos[i].S << "} ";
        cerr << "\n";

        FT aux(N + 1);

        for (int i = 0; i < N; i ++) {
                m_prev[pos[i].S] = pos[i].S;
                m_sig[pos[i].S] = pos[i].S;

                int l = 0, r = pos[i].S;
                while (l <= r) {
                        int mid = (l + r) / 2;

                        if (aux.query(mid, pos[i].S)) {
                                m_prev[pos[i].S] = mid;
                                l = mid + 1;
                        } else {
                                r = mid - 1;
                        }
                }

                l = pos[i].S, r = N - 1;
                while (l <= r) {
                        int mid = (l + r) / 2;

                        if (aux.query(pos[i].S, mid)) {
                                m_sig[pos[i].S] = mid;
                                r = mid - 1;
                        } else {
                                l = mid + 1;
                        }
                }

                aux.update(pos[i].S, 1);
        }  
}

int minimum_jumps(int A, int B, int C, int D) {
        vector<int> vis(v.size(), 1e9);
        queue<pair<int, int>> q;

        for (int i = A; i <= B; i ++) 
                q.push({i, 0});

        while (!q.empty()) {
                auto [x, d] = q.front();
                q.pop();

                if (vis[x] <= d)
                        continue;

                if (C <= x && x <= D) 
                        return d;

                vis[x] = d;

                q.push({m_sig[x], d + 1});
                q.push({m_prev[x], d + 1});
        }

        return -1;
}

Compilation message

jumps.cpp: In function 'int minimum_jumps(int, int, int, int)':
jumps.cpp:104:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  104 |                 auto [x, d] = q.front();
      |                      ^
# 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 4038 ms 8272 KB Time limit exceeded
4 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 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 2 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 2 ms 344 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 3 ms 344 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 2 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 2 ms 344 KB Output is correct
21 Correct 3 ms 344 KB Output is correct
22 Correct 2 ms 344 KB Output is correct
23 Correct 2 ms 344 KB Output is correct
24 Correct 2 ms 344 KB Output is correct
25 Correct 0 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 2 ms 344 KB Output is correct
29 Correct 2 ms 344 KB Output is correct
30 Correct 2 ms 344 KB Output is correct
31 Correct 2 ms 344 KB Output is correct
32 Correct 2 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 2 ms 344 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 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 2 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 2 ms 344 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 3 ms 344 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 2 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 2 ms 344 KB Output is correct
21 Correct 3 ms 344 KB Output is correct
22 Correct 2 ms 344 KB Output is correct
23 Correct 2 ms 344 KB Output is correct
24 Correct 2 ms 344 KB Output is correct
25 Correct 0 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 2 ms 344 KB Output is correct
29 Correct 2 ms 344 KB Output is correct
30 Correct 2 ms 344 KB Output is correct
31 Correct 2 ms 344 KB Output is correct
32 Correct 2 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 2 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 1 ms 380 KB Output is correct
45 Correct 3 ms 344 KB Output is correct
46 Correct 2 ms 344 KB Output is correct
47 Correct 2 ms 344 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 2 ms 344 KB Output is correct
50 Correct 2 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 3 ms 344 KB Output is correct
54 Correct 2 ms 344 KB Output is correct
55 Correct 2 ms 344 KB Output is correct
56 Correct 2 ms 344 KB Output is correct
57 Correct 2 ms 344 KB Output is correct
58 Correct 30 ms 344 KB Output is correct
59 Correct 40 ms 520 KB Output is correct
60 Correct 8 ms 460 KB Output is correct
61 Correct 39 ms 532 KB Output is correct
62 Correct 9 ms 344 KB Output is correct
63 Correct 47 ms 520 KB Output is correct
64 Correct 50 ms 344 KB Output is correct
65 Correct 56 ms 512 KB Output is correct
66 Correct 47 ms 344 KB Output is correct
67 Correct 43 ms 520 KB Output is correct
68 Correct 52 ms 772 KB Output is correct
69 Correct 46 ms 344 KB Output is correct
70 Correct 34 ms 508 KB Output is correct
71 Correct 0 ms 344 KB Output is correct
72 Correct 0 ms 344 KB Output is correct
73 Correct 2 ms 344 KB Output is correct
74 Correct 2 ms 344 KB Output is correct
75 Correct 4 ms 344 KB Output is correct
76 Correct 2 ms 344 KB Output is correct
77 Correct 2 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 3 ms 344 KB Output is correct
82 Correct 2 ms 344 KB Output is correct
83 Correct 2 ms 444 KB Output is correct
84 Correct 2 ms 344 KB Output is correct
85 Correct 2 ms 344 KB Output is correct
86 Correct 0 ms 344 KB Output is correct
87 Correct 1 ms 344 KB Output is correct
88 Correct 1 ms 344 KB Output is correct
89 Correct 1 ms 344 KB Output is correct
90 Correct 1 ms 344 KB Output is correct
91 Correct 1 ms 344 KB Output is correct
92 Correct 1 ms 344 KB Output is correct
93 Correct 2 ms 344 KB Output is correct
94 Correct 4 ms 460 KB Output is correct
95 Correct 42 ms 532 KB Output is correct
96 Correct 49 ms 540 KB Output is correct
97 Correct 48 ms 540 KB Output is correct
98 Correct 59 ms 352 KB Output is correct
99 Correct 57 ms 512 KB Output is correct
100 Correct 1 ms 344 KB Output is correct
101 Correct 6 ms 344 KB Output is correct
102 Correct 19 ms 512 KB Output is correct
103 Correct 33 ms 508 KB Output is correct
104 Correct 20 ms 512 KB Output is correct
105 Correct 36 ms 512 KB Output is correct
106 Correct 34 ms 344 KB Output is correct
107 Correct 1 ms 344 KB Output is correct
108 Correct 6 ms 460 KB Output is correct
109 Correct 9 ms 516 KB Output is correct
110 Correct 10 ms 512 KB Output is correct
111 Correct 11 ms 344 KB Output is correct
112 Correct 11 ms 524 KB Output is correct
113 Correct 10 ms 496 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 791 ms 7844 KB Output is correct
6 Correct 960 ms 9776 KB Output is correct
7 Correct 488 ms 4880 KB Output is correct
8 Correct 998 ms 10424 KB Output is correct
9 Correct 140 ms 1652 KB Output is correct
10 Correct 951 ms 9520 KB Output is correct
11 Correct 911 ms 9492 KB Output is correct
12 Correct 918 ms 9520 KB Output is correct
13 Correct 940 ms 9520 KB Output is correct
14 Correct 941 ms 9768 KB Output is correct
15 Correct 942 ms 9520 KB Output is correct
16 Correct 957 ms 10248 KB Output is correct
17 Correct 950 ms 10244 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 436 KB Output is correct
23 Correct 1 ms 436 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 4 ms 344 KB Output is correct
27 Correct 11 ms 340 KB Output is correct
28 Correct 11 ms 344 KB Output is correct
29 Correct 10 ms 344 KB Output is correct
30 Correct 9 ms 504 KB Output is correct
31 Correct 9 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 1010 ms 9524 KB Output is correct
34 Correct 956 ms 9560 KB Output is correct
35 Correct 900 ms 9776 KB Output is correct
36 Correct 934 ms 9620 KB Output is correct
37 Correct 945 ms 9520 KB Output is correct
38 Correct 922 ms 10620 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 537 ms 5504 KB Output is correct
41 Correct 957 ms 9640 KB Output is correct
42 Correct 925 ms 9624 KB Output is correct
43 Correct 953 ms 9524 KB Output is correct
44 Correct 969 ms 9780 KB Output is correct
45 Correct 926 ms 9636 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 1192 ms 4424 KB Output is correct
5 Execution timed out 4073 ms 9520 KB Time limit exceeded
6 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 1192 ms 4424 KB Output is correct
5 Execution timed out 4073 ms 9520 KB Time limit exceeded
6 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 4038 ms 8272 KB Time limit exceeded
4 Halted 0 ms 0 KB -