제출 #744753

#제출 시각아이디문제언어결과실행 시간메모리
744753t6twotwoRainforest Jumps (APIO21_jumps)C++17
12 / 100
4090 ms14400 KiB
#include "jumps.h" #include <bits/stdc++.h> using namespace std; int N; vector<int> H; bool subtask1; vector<vector<int>> adj; void init(int n, vector<int> h) { N = n, H = h; subtask1 = 1; for (int i = 0; i < N; i++) { H[i]--; if (i != H[i]) { subtask1 = 0; } } adj.resize(N); vector<int> stk; for (int i = N - 1; i >= 0; i--) { while (!stk.empty() && H[stk.back()] < H[i]) { stk.pop_back(); } if (!stk.empty()) { adj[H[i]].push_back(H[stk.back()]); } stk.push_back(i); } stk.clear(); for (int i = 0; i < N; i++) { while (!stk.empty() && H[stk.back()] < H[i]) { stk.pop_back(); } if (!stk.empty()) { adj[H[i]].push_back(H[stk.back()]); } stk.push_back(i); } } int minimum_jumps(int A, int B, int C, int D) { if (subtask1) { return C - B; } int ans = N; for (int i = A; i <= B; i++) { for (int j = C; j <= D; j++) { int x = H[i], cnt = 0; while (x < H[j]) { int y = -1; for (int z : adj[x]) { if (z <= H[j]) { y = max(y, z); } } if (y == -1) { break; } cnt++; x = y; } if (x == H[j]) { ans = min(ans, cnt); } } } if (ans == N) { ans = -1; } return ans; }
#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...