# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
716715 | 2023-03-30T22:13:22 Z | aryan12 | Rainforest Jumps (APIO21_jumps) | C++17 | 132 ms | 26648 KB |
#include "jumps.h" #include <bits/stdc++.h> #include <vector> using namespace std; const int MAXN = 2e5 + 5; int dp_min[19][MAXN], dp_max[19][MAXN]; vector<int> H; int N; void init(int n, std::vector<int> h) { stack<int> s; N = n; for(int i = 0; i < h.size(); i++) { H.push_back(h[i]); } for(int i = 0; i < N; i++) { while(!s.empty() && H[s.top()] < H[i]) { s.pop(); } if(s.empty()) { dp_min[0][i] = -1; } else { dp_min[0][i] = s.top(); } s.push(i); } while(!s.empty()) { s.pop(); } for(int i = N - 1; i >= 0; i--) { while(!s.empty() && H[s.top()] < H[i]) { s.pop(); } if(s.empty()) { dp_max[0][i] = -1; } else { dp_max[0][i] = s.top(); } s.push(i); if((dp_max[0][i] < dp_min[0][i] && dp_max[0][i] != -1) || (dp_min[0][i] == -1)) { swap(dp_min[0][i], dp_max[0][i]); } } for(int i = 1; i < 19; i++) { for(int j = 0; j < N; j++) { dp_min[i][j] = (dp_min[i - 1][j] == -1) ? -1 : dp_min[i - 1][dp_min[i - 1][j]]; dp_max[i][j] = (dp_max[i - 1][j] == -1) ? -1 : dp_max[i - 1][dp_max[i - 1][j]]; assert(dp_max[i][j] == -1 || H[dp_max[i][j]] >= H[dp_min[i][j]]); } } } int minimum_jumps(int A, int B, int C, int D) { // A = B && C = D int ans = 0; for(int i = 18; i >= 0; i--) { if(dp_max[i][A] != -1 && H[dp_max[i][A]] <= H[C]) { ans += (1 << i); A = dp_max[i][A]; } } for(int i = 18; i >= 0; i--) { if(dp_min[i][A] != -1 && H[dp_min[i][A]] <= H[C]) { ans += (1 << i); A = dp_min[i][A]; } } if(H[A] != H[C]) { return -1; } return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 464 KB | Output is correct |
2 | Correct | 0 ms | 464 KB | Output is correct |
3 | Incorrect | 132 ms | 26648 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 464 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 464 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 464 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 464 KB | Output is correct |
2 | Correct | 1 ms | 464 KB | Output is correct |
3 | Correct | 1 ms | 464 KB | Output is correct |
4 | Runtime error | 17 ms | 4368 KB | Execution killed with signal 6 |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 464 KB | Output is correct |
2 | Correct | 1 ms | 464 KB | Output is correct |
3 | Correct | 1 ms | 464 KB | Output is correct |
4 | Runtime error | 17 ms | 4368 KB | Execution killed with signal 6 |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 464 KB | Output is correct |
2 | Correct | 0 ms | 464 KB | Output is correct |
3 | Incorrect | 132 ms | 26648 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |