제출 #718647

#제출 시각아이디문제언어결과실행 시간메모리
718647lam밀림 점프 (APIO21_jumps)C++14
21 / 100
638 ms9312 KiB
#include "jumps.h" #include <bits/stdc++.h> #include <vector> using namespace std; const int maxn = 1e5 + 10; int n,d[maxn]; int a[maxn]; vector <int> adj[maxn]; void addedge(int u, int v) { adj[u].push_back(v); } void init(int N, std::vector<int> H) { n=N; for (int i=0; i<n; i++) a[i]=H[i],adj[i].clear(); deque<int> dq; for (int i=0; i<n; i++) { while (!dq.empty()&&a[dq.back()] < a[i]) dq.pop_back(); if (!dq.empty()) addedge(i,dq.back()); dq.push_back(i); } while (!dq.empty()) dq.pop_back(); for (int i=n-1; i>=0; i--) { while (!dq.empty()&&a[dq.back()] < a[i]) dq.pop_back(); if (!dq.empty()) addedge(i,dq.back()); dq.push_back(i); } } int minimum_jumps(int A, int B, int C, int D) { queue<int> q; fill_n(d,n,-1); // for (int i=0; i<n; i++) // { //// cerr<<i<<" : "; //// for (int j:adj[i]) cerr<<j<<' '; cerr<<endl; // } for (int i=A; i<=B; i++) { d[i]=0; q.push(i); } while (!q.empty()) { int u=q.front(); q.pop(); // cerr<<u<<endl; for (int v:adj[u]) if (d[v]==-1) { // cerr<<u<<" - "<<v<<endl; d[v]=d[u]+1; q.push(v); } } int ans=1e9; for (int i=C; i<=D; i++) if (d[i]!=-1) ans=min(ans,d[i]); if (ans==1e9) 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...