Submission #1233064

#TimeUsernameProblemLanguageResultExecution timeMemory
1233064LucaLucaMRainforest Jumps (APIO21_jumps)C++20
0 / 100
4017 ms5152 KiB
#include "jumps.h" #include <iostream> #include <vector> #include <algorithm> #include <cassert> std::vector<int> prev, next; std::vector<int> to; void init(int n, std::vector<int> p) { std::vector<int> st; prev.resize(n); next.resize(n); for (int i = 0; i < n; i++) { while (!st.empty() && p[st.back()] < p[i]) { st.pop_back(); } prev[i] = st.empty()? -1 : st.back(); st.push_back(i); } st.clear(); for (int i = n - 1; i >= 0; i--) { while (!st.empty() && p[st.back()] < p[i]) { st.pop_back(); } next[i] = st.empty()? -1 : st.back(); st.push_back(i); } st.clear(); to.resize(n); for (int i = 0; i < n; i++) { if (prev[i] == -1) { to[i] = next[i]; } else if (next[i] == -1) { to[i] = prev[i]; } else { if (p[prev[i]] < p[next[i]]) { to[i] = prev[i]; } else { to[i] = next[i]; } } } } int minimum_jumps(int A, int B, int C, int D) { int ret = 1e9; for (int i = A; i <= B; i++) { int u = i; int dist = 0; std::vector<int> vis; while (u != -1) { vis.push_back(u); if (C <= u && u <= D) { break; } u = to[u]; } if (u != -1) { dist = (int) vis.size() - 1; for (int i = 0; i + 2 < (int) vis.size(); i++) { int u = vis[i]; if (to[to[u]] == (prev[u] ^ next[u] ^ to[u])) { i++; dist--; } } ret = std::min(ret, dist); } } return ret == 1e9? -1 : ret; }
#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...