제출 #984139

#제출 시각아이디문제언어결과실행 시간메모리
984139Alkaser_ID밀림 점프 (APIO21_jumps)C++17
0 / 100
4091 ms17324 KiB
#include "jumps.h" using namespace std; #include <bits/stdc++.h> int n, dp[200005], ad[200005], a[200005]; int nxup[200005],nxls[200005],lsup[200005]; void init(int N, std::vector<int> H) { n = N; for(int i=0;i<n;++i) a[i] = H[i]; vector<pair<int,int>> v; for(int i=0;i<n;++i){ v.push_back({H[i],i}); } sort(v.begin(),v.end(),greater<pair<int,int>>()); for(int i=0;i<n;++i) nxup[i] = nxls[i] = lsup[i] = -1; set<int> s; for(int i=0;i<n;++i) { if(!s.empty()){ set<int>::iterator it= s.upper_bound(v[i].second); if(it != s.end()){ nxup[v[i].second] = *it; } if(it != s.begin()){ --it; lsup[v[i].second] = *it; } } s.insert(v[i].second); } } int minimum_jumps(int A, int B, int C, int D) { if(A == B && C == D) { if(a[C] < a[B]) return -1; int res = 0; for(;;){ if(B == C) break; if(nxup[B] == -1 || B > C) {res = -1; break;} ++res; int ls = lsup[B],nx = nxup[B]; if(a[ls] > a[nx] && a[ls] < a[C]) B = ls; else B = nx; } return res; } int res = 1e9; for(int i=C;i<=D;++i) dp[i] = 0; for(int i = A;i <= B; ++i) ad[i] = 0; for(int i=0;i < A; ++i) ad[i] = 1e9; for(int i=C-1;i>=0;i--){ int nx = nxup[i]; if(nx > D) dp[i] = 1e9; else dp[i] = dp[nx] + 1; if(i >= A && i <= B){ res = min(res,dp[i]); } int ls = lsup[i]; if(ls != -1){ ad[ls] = min(ad[ls], ad[i] + 1); } else if(i< A){ res = min(res,dp[i] + ad[i]); } } if(res >= 1e9) return -1; return res; } /* 7 3 3 2 1 6 4 5 7 4 4 6 6 1 3 5 6 0 1 2 2 */
#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...