Submission #413924

# Submission time Handle Problem Language Result Execution time Memory
413924 2021-05-29T17:27:48 Z flashmt Rainforest Jumps (APIO21_jumps) C++17
35 / 100
1665 ms 58320 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 200200;
const int LG = 19;

int n, l[N][LG], r[N][LG], high[N][LG];
vector<int> h;

int isValid(int x)
{
  return x >= 0 && x < n;
}

void initEdges()
{
  vector<pair<int, int>> sortedH;
  for (int i = 0; i < n; i++)
    sortedH.push_back({h[i], i});
  sort(sortedH.begin(), sortedH.end(), greater<pair<int, int>>());
  set<int> s;
  s.insert(-1);
  s.insert(n);
  memset(l, -1, sizeof l);
  memset(r, -1, sizeof r);
  memset(high, -1, sizeof high);
  for (auto [_, i] : sortedH)
  {
    auto it = s.lower_bound(i);
    r[i][0] = *it;
    l[i][0] = *(--it);
    if (!isValid(l[i][0]) && !isValid(r[i][0]));
    else if (!isValid(l[i][0])) high[i][0] = r[i][0];
    else if (!isValid(r[i][0])) high[i][0] = l[i][0];
    else if (h[l[i][0]] > h[r[i][0]]) high[i][0] = l[i][0];
    else high[i][0] = r[i][0];
    s.insert(i);
  }
}

void constructTable()
{
  for (int j = 0; j + 1 < LG; j++)
    for (int i = 0; i < n; i++)
    {
      if (isValid(l[i][j]))
        l[i][j + 1] = l[l[i][j]][j];
      if (isValid(r[i][j]))
        r[i][j + 1] = r[r[i][j]][j];
      if (isValid(high[i][j]))
        high[i][j + 1] = high[high[i][j]][j];
    }
}

void init(int N, vector<int> H) {
  n = N;
  h = H;
  h[n] = 0;
  initEdges();
  constructTable();
}

int jump(int &s, int table[N][LG], function<int(int)> cond)
{
  int res = 0;
  for (int i = LG - 1; i >= 0; i--)
  {
    int x = table[s][i];
    if (isValid(x) && cond(x))
    {
      s = x;
      res |= 1 << i;
    }
  }
  return res;
}

int minimum_jumps(int A, int B, int C, int D) {
  int s = B;
  // find where to start
  jump(s, l, [&](int x) {
    return x >= A && isValid(r[x][0]) && r[x][0] <= D;
  });
  // use high edges as most as possible
  int ans = jump(s, high, [&](int x) {
    return isValid(r[x][0]) && r[x][0] < C;
  });
  // check if we need to go 1 more high step
  if (isValid(r[s][0]) && r[s][0] < C)
  {
    int x = high[s][0];
    if (isValid(x) && isValid(r[x][0]) && r[x][0] <= D)
    {
      s = x;
      ans++;
    }
  }
  // just go right
  ans += jump(s, r, [&](int x) {
    return x < C;
  });
  return r[s][0] >= C && r[s][0] <= D ? ans + 1 : -1;
}
# Verdict Execution time Memory Grader output
1 Correct 20 ms 44892 KB Output is correct
2 Correct 20 ms 44872 KB Output is correct
3 Correct 267 ms 55500 KB Output is correct
4 Correct 1325 ms 58252 KB Output is correct
5 Correct 1249 ms 51624 KB Output is correct
6 Correct 1391 ms 58160 KB Output is correct
7 Correct 1075 ms 53936 KB Output is correct
8 Correct 1264 ms 58248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 44872 KB Output is correct
2 Correct 21 ms 44872 KB Output is correct
3 Correct 22 ms 44864 KB Output is correct
4 Correct 21 ms 44872 KB Output is correct
5 Correct 23 ms 44872 KB Output is correct
6 Correct 22 ms 44872 KB Output is correct
7 Correct 22 ms 44864 KB Output is correct
8 Correct 24 ms 44852 KB Output is correct
9 Correct 22 ms 44920 KB Output is correct
10 Correct 24 ms 44872 KB Output is correct
11 Correct 22 ms 44872 KB Output is correct
12 Correct 24 ms 44924 KB Output is correct
13 Correct 24 ms 44908 KB Output is correct
14 Correct 24 ms 44872 KB Output is correct
15 Correct 25 ms 44852 KB Output is correct
16 Correct 22 ms 44872 KB Output is correct
17 Correct 26 ms 44880 KB Output is correct
18 Correct 22 ms 44872 KB Output is correct
19 Correct 22 ms 44944 KB Output is correct
20 Correct 24 ms 44940 KB Output is correct
21 Correct 24 ms 44876 KB Output is correct
22 Correct 25 ms 44872 KB Output is correct
23 Correct 22 ms 44872 KB Output is correct
24 Correct 23 ms 44872 KB Output is correct
25 Correct 21 ms 44940 KB Output is correct
26 Correct 21 ms 44872 KB Output is correct
27 Correct 23 ms 44872 KB Output is correct
28 Correct 27 ms 44836 KB Output is correct
29 Correct 25 ms 44912 KB Output is correct
30 Correct 23 ms 44872 KB Output is correct
31 Correct 23 ms 44872 KB Output is correct
32 Correct 24 ms 44872 KB Output is correct
33 Correct 21 ms 44872 KB Output is correct
34 Correct 20 ms 44872 KB Output is correct
35 Correct 21 ms 44908 KB Output is correct
36 Correct 21 ms 44952 KB Output is correct
37 Correct 21 ms 44876 KB Output is correct
38 Correct 22 ms 45000 KB Output is correct
39 Correct 22 ms 44872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 44872 KB Output is correct
2 Correct 21 ms 44872 KB Output is correct
3 Correct 22 ms 44864 KB Output is correct
4 Correct 21 ms 44872 KB Output is correct
5 Correct 23 ms 44872 KB Output is correct
6 Correct 22 ms 44872 KB Output is correct
7 Correct 22 ms 44864 KB Output is correct
8 Correct 24 ms 44852 KB Output is correct
9 Correct 22 ms 44920 KB Output is correct
10 Correct 24 ms 44872 KB Output is correct
11 Correct 22 ms 44872 KB Output is correct
12 Correct 24 ms 44924 KB Output is correct
13 Correct 24 ms 44908 KB Output is correct
14 Correct 24 ms 44872 KB Output is correct
15 Correct 25 ms 44852 KB Output is correct
16 Correct 22 ms 44872 KB Output is correct
17 Correct 26 ms 44880 KB Output is correct
18 Correct 22 ms 44872 KB Output is correct
19 Correct 22 ms 44944 KB Output is correct
20 Correct 24 ms 44940 KB Output is correct
21 Correct 24 ms 44876 KB Output is correct
22 Correct 25 ms 44872 KB Output is correct
23 Correct 22 ms 44872 KB Output is correct
24 Correct 23 ms 44872 KB Output is correct
25 Correct 21 ms 44940 KB Output is correct
26 Correct 21 ms 44872 KB Output is correct
27 Correct 23 ms 44872 KB Output is correct
28 Correct 27 ms 44836 KB Output is correct
29 Correct 25 ms 44912 KB Output is correct
30 Correct 23 ms 44872 KB Output is correct
31 Correct 23 ms 44872 KB Output is correct
32 Correct 24 ms 44872 KB Output is correct
33 Correct 21 ms 44872 KB Output is correct
34 Correct 20 ms 44872 KB Output is correct
35 Correct 21 ms 44908 KB Output is correct
36 Correct 21 ms 44952 KB Output is correct
37 Correct 21 ms 44876 KB Output is correct
38 Correct 22 ms 45000 KB Output is correct
39 Correct 22 ms 44872 KB Output is correct
40 Correct 21 ms 44872 KB Output is correct
41 Correct 21 ms 44944 KB Output is correct
42 Correct 21 ms 44808 KB Output is correct
43 Correct 22 ms 44872 KB Output is correct
44 Correct 22 ms 44872 KB Output is correct
45 Correct 24 ms 44856 KB Output is correct
46 Correct 24 ms 44872 KB Output is correct
47 Correct 23 ms 44872 KB Output is correct
48 Correct 22 ms 44948 KB Output is correct
49 Correct 24 ms 44872 KB Output is correct
50 Correct 22 ms 44872 KB Output is correct
51 Correct 24 ms 44872 KB Output is correct
52 Correct 24 ms 44932 KB Output is correct
53 Correct 25 ms 44872 KB Output is correct
54 Correct 25 ms 44844 KB Output is correct
55 Correct 22 ms 44872 KB Output is correct
56 Correct 23 ms 44952 KB Output is correct
57 Correct 21 ms 44936 KB Output is correct
58 Correct 42 ms 45000 KB Output is correct
59 Correct 44 ms 45036 KB Output is correct
60 Correct 28 ms 44956 KB Output is correct
61 Correct 43 ms 45000 KB Output is correct
62 Correct 40 ms 44872 KB Output is correct
63 Correct 48 ms 45076 KB Output is correct
64 Correct 40 ms 44992 KB Output is correct
65 Correct 49 ms 45000 KB Output is correct
66 Correct 47 ms 45032 KB Output is correct
67 Correct 38 ms 45044 KB Output is correct
68 Correct 48 ms 45000 KB Output is correct
69 Correct 52 ms 45000 KB Output is correct
70 Correct 51 ms 44988 KB Output is correct
71 Correct 21 ms 44872 KB Output is correct
72 Correct 22 ms 44900 KB Output is correct
73 Correct 23 ms 44864 KB Output is correct
74 Correct 23 ms 44960 KB Output is correct
75 Correct 23 ms 44952 KB Output is correct
76 Correct 24 ms 44872 KB Output is correct
77 Correct 24 ms 44848 KB Output is correct
78 Correct 21 ms 44944 KB Output is correct
79 Correct 20 ms 44872 KB Output is correct
80 Correct 22 ms 44868 KB Output is correct
81 Correct 23 ms 44844 KB Output is correct
82 Correct 23 ms 44872 KB Output is correct
83 Correct 23 ms 44876 KB Output is correct
84 Correct 23 ms 44872 KB Output is correct
85 Correct 22 ms 44872 KB Output is correct
86 Correct 21 ms 44864 KB Output is correct
87 Correct 22 ms 44852 KB Output is correct
88 Correct 21 ms 44872 KB Output is correct
89 Correct 21 ms 44872 KB Output is correct
90 Correct 22 ms 44872 KB Output is correct
91 Correct 20 ms 44872 KB Output is correct
92 Correct 21 ms 44952 KB Output is correct
93 Correct 22 ms 44872 KB Output is correct
94 Runtime error 3 ms 328 KB Execution killed with signal 6
95 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 44872 KB Output is correct
2 Correct 20 ms 44872 KB Output is correct
3 Correct 20 ms 44908 KB Output is correct
4 Correct 22 ms 44932 KB Output is correct
5 Correct 205 ms 55564 KB Output is correct
6 Correct 280 ms 58188 KB Output is correct
7 Correct 125 ms 51708 KB Output is correct
8 Correct 273 ms 58280 KB Output is correct
9 Runtime error 7 ms 1096 KB Execution killed with signal 6
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 44872 KB Output is correct
2 Correct 22 ms 44944 KB Output is correct
3 Correct 21 ms 44836 KB Output is correct
4 Correct 409 ms 50924 KB Output is correct
5 Correct 1237 ms 58288 KB Output is correct
6 Correct 792 ms 47144 KB Output is correct
7 Correct 1167 ms 58256 KB Output is correct
8 Correct 639 ms 49460 KB Output is correct
9 Correct 1341 ms 58160 KB Output is correct
10 Correct 1474 ms 58260 KB Output is correct
11 Correct 1636 ms 58160 KB Output is correct
12 Correct 1517 ms 58292 KB Output is correct
13 Correct 1333 ms 58204 KB Output is correct
14 Correct 1390 ms 58240 KB Output is correct
15 Correct 1103 ms 58240 KB Output is correct
16 Correct 1363 ms 58292 KB Output is correct
17 Correct 22 ms 44872 KB Output is correct
18 Correct 22 ms 44872 KB Output is correct
19 Correct 23 ms 44944 KB Output is correct
20 Correct 25 ms 44872 KB Output is correct
21 Correct 23 ms 44864 KB Output is correct
22 Correct 25 ms 44888 KB Output is correct
23 Correct 24 ms 44920 KB Output is correct
24 Correct 22 ms 44872 KB Output is correct
25 Correct 21 ms 44872 KB Output is correct
26 Correct 22 ms 45000 KB Output is correct
27 Correct 41 ms 45064 KB Output is correct
28 Correct 48 ms 44996 KB Output is correct
29 Correct 43 ms 45000 KB Output is correct
30 Correct 47 ms 45000 KB Output is correct
31 Correct 39 ms 45000 KB Output is correct
32 Correct 23 ms 44872 KB Output is correct
33 Correct 144 ms 52572 KB Output is correct
34 Correct 275 ms 58248 KB Output is correct
35 Correct 190 ms 58256 KB Output is correct
36 Correct 232 ms 58232 KB Output is correct
37 Correct 248 ms 58196 KB Output is correct
38 Correct 201 ms 58292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 44872 KB Output is correct
2 Correct 22 ms 44944 KB Output is correct
3 Correct 21 ms 44836 KB Output is correct
4 Correct 409 ms 50924 KB Output is correct
5 Correct 1237 ms 58288 KB Output is correct
6 Correct 792 ms 47144 KB Output is correct
7 Correct 1167 ms 58256 KB Output is correct
8 Correct 639 ms 49460 KB Output is correct
9 Correct 1341 ms 58160 KB Output is correct
10 Correct 1474 ms 58260 KB Output is correct
11 Correct 1636 ms 58160 KB Output is correct
12 Correct 1517 ms 58292 KB Output is correct
13 Correct 1333 ms 58204 KB Output is correct
14 Correct 1390 ms 58240 KB Output is correct
15 Correct 1103 ms 58240 KB Output is correct
16 Correct 1363 ms 58292 KB Output is correct
17 Correct 22 ms 44872 KB Output is correct
18 Correct 22 ms 44872 KB Output is correct
19 Correct 23 ms 44944 KB Output is correct
20 Correct 25 ms 44872 KB Output is correct
21 Correct 23 ms 44864 KB Output is correct
22 Correct 25 ms 44888 KB Output is correct
23 Correct 24 ms 44920 KB Output is correct
24 Correct 22 ms 44872 KB Output is correct
25 Correct 21 ms 44872 KB Output is correct
26 Correct 22 ms 45000 KB Output is correct
27 Correct 41 ms 45064 KB Output is correct
28 Correct 48 ms 44996 KB Output is correct
29 Correct 43 ms 45000 KB Output is correct
30 Correct 47 ms 45000 KB Output is correct
31 Correct 39 ms 45000 KB Output is correct
32 Correct 23 ms 44872 KB Output is correct
33 Correct 144 ms 52572 KB Output is correct
34 Correct 275 ms 58248 KB Output is correct
35 Correct 190 ms 58256 KB Output is correct
36 Correct 232 ms 58232 KB Output is correct
37 Correct 248 ms 58196 KB Output is correct
38 Correct 201 ms 58292 KB Output is correct
39 Correct 23 ms 44872 KB Output is correct
40 Correct 21 ms 44872 KB Output is correct
41 Correct 20 ms 44884 KB Output is correct
42 Correct 341 ms 50960 KB Output is correct
43 Correct 1400 ms 58164 KB Output is correct
44 Correct 909 ms 47032 KB Output is correct
45 Correct 1308 ms 58160 KB Output is correct
46 Correct 776 ms 49580 KB Output is correct
47 Correct 991 ms 58280 KB Output is correct
48 Correct 1488 ms 58156 KB Output is correct
49 Correct 1012 ms 58144 KB Output is correct
50 Correct 1355 ms 58252 KB Output is correct
51 Correct 1365 ms 58244 KB Output is correct
52 Correct 1580 ms 58280 KB Output is correct
53 Correct 1477 ms 58276 KB Output is correct
54 Correct 1438 ms 58160 KB Output is correct
55 Correct 21 ms 44872 KB Output is correct
56 Correct 381 ms 58144 KB Output is correct
57 Correct 1232 ms 58320 KB Output is correct
58 Correct 584 ms 47244 KB Output is correct
59 Correct 1195 ms 58192 KB Output is correct
60 Correct 472 ms 49588 KB Output is correct
61 Correct 1251 ms 58160 KB Output is correct
62 Correct 1415 ms 58252 KB Output is correct
63 Correct 1390 ms 58212 KB Output is correct
64 Correct 1478 ms 58240 KB Output is correct
65 Correct 1421 ms 58144 KB Output is correct
66 Correct 1665 ms 58236 KB Output is correct
67 Correct 1407 ms 58140 KB Output is correct
68 Correct 1479 ms 58160 KB Output is correct
69 Correct 21 ms 44844 KB Output is correct
70 Correct 23 ms 44872 KB Output is correct
71 Correct 24 ms 44864 KB Output is correct
72 Correct 23 ms 44924 KB Output is correct
73 Correct 24 ms 44872 KB Output is correct
74 Correct 25 ms 44872 KB Output is correct
75 Correct 23 ms 44864 KB Output is correct
76 Correct 21 ms 44848 KB Output is correct
77 Correct 21 ms 44940 KB Output is correct
78 Correct 25 ms 44824 KB Output is correct
79 Correct 24 ms 44852 KB Output is correct
80 Correct 24 ms 44872 KB Output is correct
81 Correct 24 ms 44956 KB Output is correct
82 Correct 24 ms 44872 KB Output is correct
83 Correct 23 ms 44868 KB Output is correct
84 Correct 22 ms 44844 KB Output is correct
85 Runtime error 3 ms 328 KB Execution killed with signal 6
86 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 44892 KB Output is correct
2 Correct 20 ms 44872 KB Output is correct
3 Correct 267 ms 55500 KB Output is correct
4 Correct 1325 ms 58252 KB Output is correct
5 Correct 1249 ms 51624 KB Output is correct
6 Correct 1391 ms 58160 KB Output is correct
7 Correct 1075 ms 53936 KB Output is correct
8 Correct 1264 ms 58248 KB Output is correct
9 Correct 22 ms 44872 KB Output is correct
10 Correct 21 ms 44872 KB Output is correct
11 Correct 22 ms 44864 KB Output is correct
12 Correct 21 ms 44872 KB Output is correct
13 Correct 23 ms 44872 KB Output is correct
14 Correct 22 ms 44872 KB Output is correct
15 Correct 22 ms 44864 KB Output is correct
16 Correct 24 ms 44852 KB Output is correct
17 Correct 22 ms 44920 KB Output is correct
18 Correct 24 ms 44872 KB Output is correct
19 Correct 22 ms 44872 KB Output is correct
20 Correct 24 ms 44924 KB Output is correct
21 Correct 24 ms 44908 KB Output is correct
22 Correct 24 ms 44872 KB Output is correct
23 Correct 25 ms 44852 KB Output is correct
24 Correct 22 ms 44872 KB Output is correct
25 Correct 26 ms 44880 KB Output is correct
26 Correct 22 ms 44872 KB Output is correct
27 Correct 22 ms 44944 KB Output is correct
28 Correct 24 ms 44940 KB Output is correct
29 Correct 24 ms 44876 KB Output is correct
30 Correct 25 ms 44872 KB Output is correct
31 Correct 22 ms 44872 KB Output is correct
32 Correct 23 ms 44872 KB Output is correct
33 Correct 21 ms 44940 KB Output is correct
34 Correct 21 ms 44872 KB Output is correct
35 Correct 23 ms 44872 KB Output is correct
36 Correct 27 ms 44836 KB Output is correct
37 Correct 25 ms 44912 KB Output is correct
38 Correct 23 ms 44872 KB Output is correct
39 Correct 23 ms 44872 KB Output is correct
40 Correct 24 ms 44872 KB Output is correct
41 Correct 21 ms 44872 KB Output is correct
42 Correct 20 ms 44872 KB Output is correct
43 Correct 21 ms 44908 KB Output is correct
44 Correct 21 ms 44952 KB Output is correct
45 Correct 21 ms 44876 KB Output is correct
46 Correct 22 ms 45000 KB Output is correct
47 Correct 22 ms 44872 KB Output is correct
48 Correct 21 ms 44872 KB Output is correct
49 Correct 21 ms 44944 KB Output is correct
50 Correct 21 ms 44808 KB Output is correct
51 Correct 22 ms 44872 KB Output is correct
52 Correct 22 ms 44872 KB Output is correct
53 Correct 24 ms 44856 KB Output is correct
54 Correct 24 ms 44872 KB Output is correct
55 Correct 23 ms 44872 KB Output is correct
56 Correct 22 ms 44948 KB Output is correct
57 Correct 24 ms 44872 KB Output is correct
58 Correct 22 ms 44872 KB Output is correct
59 Correct 24 ms 44872 KB Output is correct
60 Correct 24 ms 44932 KB Output is correct
61 Correct 25 ms 44872 KB Output is correct
62 Correct 25 ms 44844 KB Output is correct
63 Correct 22 ms 44872 KB Output is correct
64 Correct 23 ms 44952 KB Output is correct
65 Correct 21 ms 44936 KB Output is correct
66 Correct 42 ms 45000 KB Output is correct
67 Correct 44 ms 45036 KB Output is correct
68 Correct 28 ms 44956 KB Output is correct
69 Correct 43 ms 45000 KB Output is correct
70 Correct 40 ms 44872 KB Output is correct
71 Correct 48 ms 45076 KB Output is correct
72 Correct 40 ms 44992 KB Output is correct
73 Correct 49 ms 45000 KB Output is correct
74 Correct 47 ms 45032 KB Output is correct
75 Correct 38 ms 45044 KB Output is correct
76 Correct 48 ms 45000 KB Output is correct
77 Correct 52 ms 45000 KB Output is correct
78 Correct 51 ms 44988 KB Output is correct
79 Correct 21 ms 44872 KB Output is correct
80 Correct 22 ms 44900 KB Output is correct
81 Correct 23 ms 44864 KB Output is correct
82 Correct 23 ms 44960 KB Output is correct
83 Correct 23 ms 44952 KB Output is correct
84 Correct 24 ms 44872 KB Output is correct
85 Correct 24 ms 44848 KB Output is correct
86 Correct 21 ms 44944 KB Output is correct
87 Correct 20 ms 44872 KB Output is correct
88 Correct 22 ms 44868 KB Output is correct
89 Correct 23 ms 44844 KB Output is correct
90 Correct 23 ms 44872 KB Output is correct
91 Correct 23 ms 44876 KB Output is correct
92 Correct 23 ms 44872 KB Output is correct
93 Correct 22 ms 44872 KB Output is correct
94 Correct 21 ms 44864 KB Output is correct
95 Correct 22 ms 44852 KB Output is correct
96 Correct 21 ms 44872 KB Output is correct
97 Correct 21 ms 44872 KB Output is correct
98 Correct 22 ms 44872 KB Output is correct
99 Correct 20 ms 44872 KB Output is correct
100 Correct 21 ms 44952 KB Output is correct
101 Correct 22 ms 44872 KB Output is correct
102 Runtime error 3 ms 328 KB Execution killed with signal 6
103 Halted 0 ms 0 KB -