제출 #1120002

#제출 시각아이디문제언어결과실행 시간메모리
1120002dsyz밀림 점프 (APIO21_jumps)C++17
33 / 100
4070 ms34188 KiB
#include <bits/stdc++.h> #include "jumps.h" using namespace std; using ll = long long; #define MAXN (1000005) ll N; vector<ll> v[MAXN]; void init(int n, vector<int> H){ N = n; stack<ll> s; for(ll i = 0;i < N;i++){ while(!s.empty() && H[s.top()] < H[i]){ s.pop(); } if(!s.empty()){ v[i].push_back(s.top()); } s.push(i); } while(!s.empty()){ s.pop(); } for(ll i = N - 1;i >= 0;i--){ while(!s.empty() && H[s.top()] < H[i]){ s.pop(); } if(!s.empty()){ v[i].push_back(s.top()); } s.push(i); } } int minimum_jumps(int A, int B, int C, int D){ queue<ll> q; ll dist[N]; memset(dist,-1,sizeof(dist)); for(ll i = A;i <= B;i++){ q.push(i); dist[i] = 0; } while(!q.empty()){ ll x = q.front(); q.pop(); for(auto u : v[x]){ if(dist[u] == -1){ q.push(u); dist[u] = dist[x] + 1; } } } ll mini = 1e18; for(ll i = C;i <= D;i++){ if(dist[i] == -1) continue; mini = min(mini,dist[i]); } if(mini == 1e18) return -1; else return mini; }
#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...