Submission #478214

# Submission time Handle Problem Language Result Execution time Memory
478214 2021-10-06T13:35:44 Z khoabright Rainforest Jumps (APIO21_jumps) C++17
27 / 100
1343 ms 50480 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
 
constexpr int kMaxLogN = 20;
 
int N;
vector<int> H;
vector<vector<int>> L, R;
vector<vector<int>> higher;
 
void init(int _N, std::vector<int> _H) {
  N = _N;
  H = _H;
 
  H.insert(H.begin(), INT_MAX);
  H.insert(H.end(), INT_MAX);
  N += 2;
  L = R = higher = vector<vector<int>>(kMaxLogN, vector<int>(N));
 
  stack<int> decreasing_height;
  for (int i = 0; i < N; ++i) {
    while (!decreasing_height.empty() && H[decreasing_height.top()] <= H[i]) {
      decreasing_height.pop();
    }
    L[0][i] = decreasing_height.empty() ? i : decreasing_height.top();
    decreasing_height.push(i);
  }
 
  while (!decreasing_height.empty()) {
    decreasing_height.pop();
  }
  for (int i = N - 1; i >= 0; --i) {
    while (!decreasing_height.empty() && H[decreasing_height.top()] <= H[i]) {
      decreasing_height.pop();
    }
    R[0][i] = decreasing_height.empty() ? i : decreasing_height.top();
    decreasing_height.push(i);
  }
 
  for (int i = 0; i < N; ++i) {
    higher[0][i] = H[L[0][i]] > H[R[0][i]] ? L[0][i] : R[0][i];
  }
 
  for (int j = 1; j < kMaxLogN; ++j) {
    for (int i = 0; i < N; ++i) {
      L[j][i] = L[j - 1][L[j - 1][i]];
      R[j][i] = R[j - 1][R[j - 1][i]];
      higher[j][i] = higher[j - 1][higher[j - 1][i]];
    }
  }
}
 
int minimum_jumps(int s, int e) {
  int jumps = 0;
  for (int j = kMaxLogN - 1; j >= 0; --j) {
    if (H[higher[j][s]] <= H[e]) {
      s = higher[j][s];
      jumps |= (1 << j);
    }
  }
  if (H[L[0][s]] > H[e]) {
    for (int j = kMaxLogN - 1; j >= 0; --j) {
      if (H[R[j][s]] <= H[e]) {
        s = R[j][s];
        jumps += (1 << j);
      }
    }
  } 
  
  return s == e ? jumps : -1;
}
 
int minimum_jumps(int A, int B, int C, int D) {
  ++A; ++B; ++C; ++D;
 
  return minimum_jumps(B, C);
}
# 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 173 ms 40112 KB Output is correct
4 Correct 1343 ms 50436 KB Output is correct
5 Correct 963 ms 25508 KB Output is correct
6 Correct 1201 ms 50352 KB Output is correct
7 Correct 990 ms 34472 KB Output is correct
8 Correct 1238 ms 50432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 200 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 200 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 200 KB Output isn't correct
2 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 0 ms 200 KB Output is correct
4 Correct 296 ms 23088 KB Output is correct
5 Correct 1218 ms 50352 KB Output is correct
6 Correct 826 ms 8516 KB Output is correct
7 Correct 1222 ms 50352 KB Output is correct
8 Correct 533 ms 17464 KB Output is correct
9 Correct 990 ms 50324 KB Output is correct
10 Correct 1337 ms 50452 KB Output is correct
11 Correct 1094 ms 50312 KB Output is correct
12 Correct 1072 ms 50352 KB Output is correct
13 Correct 812 ms 50352 KB Output is correct
14 Correct 1150 ms 50312 KB Output is correct
15 Correct 903 ms 50356 KB Output is correct
16 Correct 1088 ms 50432 KB Output is correct
17 Correct 0 ms 200 KB Output is correct
18 Correct 1 ms 200 KB Output is correct
19 Correct 2 ms 200 KB Output is correct
20 Correct 2 ms 328 KB Output is correct
21 Correct 3 ms 328 KB Output is correct
22 Correct 2 ms 328 KB Output is correct
23 Correct 3 ms 328 KB Output is correct
24 Correct 2 ms 328 KB Output is correct
25 Correct 0 ms 328 KB Output is correct
26 Correct 2 ms 456 KB Output is correct
27 Correct 25 ms 776 KB Output is correct
28 Correct 22 ms 712 KB Output is correct
29 Correct 21 ms 788 KB Output is correct
30 Correct 23 ms 676 KB Output is correct
31 Correct 21 ms 712 KB Output is correct
32 Correct 0 ms 200 KB Output is correct
33 Correct 41 ms 29284 KB Output is correct
34 Correct 66 ms 50296 KB Output is correct
35 Correct 59 ms 50440 KB Output is correct
36 Correct 67 ms 50356 KB Output is correct
37 Correct 62 ms 50352 KB Output is correct
38 Correct 61 ms 50352 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 296 ms 23088 KB Output is correct
5 Correct 1218 ms 50352 KB Output is correct
6 Correct 826 ms 8516 KB Output is correct
7 Correct 1222 ms 50352 KB Output is correct
8 Correct 533 ms 17464 KB Output is correct
9 Correct 990 ms 50324 KB Output is correct
10 Correct 1337 ms 50452 KB Output is correct
11 Correct 1094 ms 50312 KB Output is correct
12 Correct 1072 ms 50352 KB Output is correct
13 Correct 812 ms 50352 KB Output is correct
14 Correct 1150 ms 50312 KB Output is correct
15 Correct 903 ms 50356 KB Output is correct
16 Correct 1088 ms 50432 KB Output is correct
17 Correct 0 ms 200 KB Output is correct
18 Correct 1 ms 200 KB Output is correct
19 Correct 2 ms 200 KB Output is correct
20 Correct 2 ms 328 KB Output is correct
21 Correct 3 ms 328 KB Output is correct
22 Correct 2 ms 328 KB Output is correct
23 Correct 3 ms 328 KB Output is correct
24 Correct 2 ms 328 KB Output is correct
25 Correct 0 ms 328 KB Output is correct
26 Correct 2 ms 456 KB Output is correct
27 Correct 25 ms 776 KB Output is correct
28 Correct 22 ms 712 KB Output is correct
29 Correct 21 ms 788 KB Output is correct
30 Correct 23 ms 676 KB Output is correct
31 Correct 21 ms 712 KB Output is correct
32 Correct 0 ms 200 KB Output is correct
33 Correct 41 ms 29284 KB Output is correct
34 Correct 66 ms 50296 KB Output is correct
35 Correct 59 ms 50440 KB Output is correct
36 Correct 67 ms 50356 KB Output is correct
37 Correct 62 ms 50352 KB Output is correct
38 Correct 61 ms 50352 KB Output is correct
39 Correct 0 ms 200 KB Output is correct
40 Correct 0 ms 200 KB Output is correct
41 Correct 0 ms 200 KB Output is correct
42 Correct 235 ms 23076 KB Output is correct
43 Correct 1208 ms 50356 KB Output is correct
44 Correct 860 ms 8516 KB Output is correct
45 Correct 873 ms 50352 KB Output is correct
46 Correct 658 ms 17456 KB Output is correct
47 Correct 1087 ms 50292 KB Output is correct
48 Correct 1265 ms 50352 KB Output is correct
49 Correct 1043 ms 50352 KB Output is correct
50 Correct 1159 ms 50308 KB Output is correct
51 Correct 910 ms 50308 KB Output is correct
52 Correct 1120 ms 50480 KB Output is correct
53 Correct 876 ms 50312 KB Output is correct
54 Correct 863 ms 50352 KB Output is correct
55 Correct 0 ms 200 KB Output is correct
56 Incorrect 134 ms 50172 KB Output isn't correct
57 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 173 ms 40112 KB Output is correct
4 Correct 1343 ms 50436 KB Output is correct
5 Correct 963 ms 25508 KB Output is correct
6 Correct 1201 ms 50352 KB Output is correct
7 Correct 990 ms 34472 KB Output is correct
8 Correct 1238 ms 50432 KB Output is correct
9 Incorrect 0 ms 200 KB Output isn't correct
10 Halted 0 ms 0 KB -