Submission #440630

#TimeUsernameProblemLanguageResultExecution timeMemory
440630ElegiaRainforest Jumps (APIO21_jumps)C++17
4 / 100
1116 ms30880 KiB
#include "jumps.h" const int MAX_N = 200010, L = 18; int N; int h[MAX_N], left[MAX_N][L], right[MAX_N][L]; void init(int _N, std::vector<int> _H) { N = _N; std::copy(_H.begin(), _H.end(), h + 1); static int stack[MAX_N]; int cnt = 0; for (int i = 1; i <= N; ++i) { while (cnt && h[i] > h[stack[cnt]]) right[stack[cnt--]][0] = i; left[i][0] = stack[cnt]; stack[++cnt] = i; } for (int i = 1; i <= N; ++i) for (int j = 1; j != L; ++j) left[i][j] = left[left[i][j - 1]][j - 1]; std::fill(right[N + 1], right[N + 1] + L, N + 1); for (int i = N; i; --i) { if (!right[i][0]) right[i][0] = N + 1; for (int j = 1; j != L; ++j) right[i][j] = right[right[i][j - 1]][j - 1]; } } int minimum_jumps(int A, int B, int C, int D) { ++A; ++B; ++C; ++D; for (int i = L - 1; i >= 0; --i) if (left[D][i] >= C) D = left[D][i]; for (int i = L - 1; i >= 0; --i) if (left[B][i] >= A && h[left[B][i]] < h[D]) B = left[B][i]; int ret = 0; for (int i = L - 1; i >= 0; --i) if (right[B][i] < C) { ret |= 1 << i; B = right[B][i]; } if (h[B] > h[D]) return -1; return ret + 1; }
#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...