제출 #1202320

#제출 시각아이디문제언어결과실행 시간메모리
1202320jer033밀림 점프 (APIO21_jumps)C++20
33 / 100
4101 ms33292 KiB
#include "jumps.h" #include <vector> #include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; const int INF = 500'005; int n; vector<vector<int>> edgelist; void init(int N, std::vector<int> H) { n = N; edgelist = vector<vector<int>> (N+2); set<int> trees; trees.insert(0); trees.insert(N+1); set<int> hanging_trees; hanging_trees.insert(0); hanging_trees.insert(-N-1); vector<pii> heightmap; for (int i=0; i<N; i++) heightmap.push_back({H[i], i+1}); sort(heightmap.begin(), heightmap.end()); for (int ind=N-1; ind>=0; ind--) { int next_tall = heightmap[ind].second; edgelist[next_tall].push_back(0 - *(hanging_trees.lower_bound(0-next_tall))); edgelist[next_tall].push_back( *( trees.lower_bound( next_tall))); hanging_trees.insert(0-next_tall); trees.insert(next_tall); } } int minimum_jumps(int A, int B, int C, int D) { A++; B++; C++; D++; vector<int> dists(n+2, INF); queue<int> qq; for (int i=A; i<=B; i++) { dists[i] = 0; qq.push(i); } while (!qq.empty()) { int x = qq.front(); qq.pop(); for (int y: edgelist[x]) if (dists[y]==INF) { dists[y] = dists[x]+1; qq.push(y); if ((C<=y) and (y<=D)) return dists[y]; } } 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...