제출 #555486

#제출 시각아이디문제언어결과실행 시간메모리
555486joelau밀림 점프 (APIO21_jumps)C++14
33 / 100
4024 ms14080 KiB
#include "jumps.h" #include <bits/stdc++.h> using namespace std; int n,dist[200005]; vector<int> lst[200005]; stack<int> s; queue<int> q; void init(int N, std::vector<int> H) { n = N; for (int i = 0; i < N; ++i) { while (!s.empty() && H[i] >= H[s.top()]) s.pop(); if (!s.empty()) lst[i].push_back(s.top()); s.push(i); } while (!s.empty()) s.pop(); for (int i = N-1; i >= 0; --i) { while (!s.empty() && H[i] >= H[s.top()]) s.pop(); if (!s.empty()) lst[i].push_back(s.top()); s.push(i); } } int minimum_jumps(int A, int B, int C, int D) { while (!q.empty()) q.pop(); for (int i = 0; i < n; ++i) dist[i] = -1; for (int i = A; i <= B; ++i) { dist[i] = 0; q.push(i); } while (!q.empty()) { int u = q.front(); q.pop(); if (u >= C && u <= D) return dist[u]; for (int v: lst[u]) if (dist[v] == -1) { dist[v] = dist[u] + 1; q.push(v); } } return -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...