제출 #744943

#제출 시각아이디문제언어결과실행 시간메모리
744943RushB밀림 점프 (APIO21_jumps)C++17
23 / 100
1048 ms39892 KiB
#include "jumps.h" #include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); i++) using namespace std; const int N = 2e5 + 5; const int L = 20; int prv[N], nxt[N], n, h[N], sparse[N][L]; vector<int> H; void init(int _n, std::vector<int> _H) { n = _n; H.swap(_H); vector<int> st; FOR(i, 0, n) { while (st.size() && H[st.back()] <= H[i]) st.pop_back(); prv[i] = (st.empty() ? -1 : st.back()); st.push_back(i); } st.clear(); for (int i = n - 1; i >= 0; i--) { while (st.size() && H[st.back()] <= H[i]) st.pop_back(); nxt[i] = (st.empty() ? n : st.back()); st.push_back(i); } for (int i = n - 1; i >= 0; i--) h[i] = h[nxt[i]] + 1; for (int i = 0; i < n; i++) { int x = (prv[i] == -1 ? -1 : H[prv[i]]), y = (nxt[i] == n ? -1 : H[nxt[i]]); if (y == -1 && x == -1) sparse[i][0] = i; else sparse[i][0] = (x > y ? prv[i] : nxt[i]); } FOR(j, 1, L) FOR(i, 0, n) sparse[i][j] = sparse[sparse[i][j - 1]][j - 1]; } int minimum_jumps(int A, int B, int C, int D) { assert(A == B && C == D); if (prv[C] >= A) return -1; int t = 0; for (int i = L - 1; i >= 0; i--) if (H[sparse[A][i]] < H[C]) { A = sparse[A][i]; t |= 1 << i; } return t + h[A] - h[C]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...