제출 #1061597

#제출 시각아이디문제언어결과실행 시간메모리
1061597alexdd밀림 점프 (APIO21_jumps)C++17
33 / 100
4082 ms6488 KiB
#include "jumps.h" #include <bits/stdc++.h> using namespace std; vector<int> H; int unde[200005]; const int INF = 1e9; int parent[200005]; int tole[200005],tori[200005]; void init(int N, std::vector<int> copH) { H=copH; deque<int> dq; for(int i=0;i<N;i++) { unde[H[i]]=i; while(!dq.empty() && H[dq.back()] < H[i]) dq.pop_back(); if(dq.empty()) tole[i]=-1; else tole[i]=dq.back(); dq.push_back(i); } dq.clear(); for(int i=N-1;i>=0;i--) { while(!dq.empty() && H[dq.back()] < H[i]) dq.pop_back(); if(dq.empty()) tori[i]=N; else tori[i]=dq.back(); dq.push_back(i); } } int getmax(int le, int ri) { int mxm=0; for(int i=le;i<=ri;i++) mxm = max(mxm, H[i]); return mxm; } int getdist(int cur, int le, int ri) { int pasi=0,mxm=getmax(le,ri); while(1) { if(tori[cur]>ri || H[cur] > mxm) return INF; if(tori[cur]>=le && tori[cur]<=ri) return pasi+1; if(H[tole[cur]] > H[tori[cur]] && H[tole[cur]] < mxm) { cur = tole[cur]; } else { cur = tori[cur]; } pasi++; } return pasi; } int minimum_jumps(int A, int B, int C, int D) { if(getmax(B+1,C-1) > getmax(C,D)) return -1; if(H[B] > getmax(C,D)) return -1; int st=A,dr=B,primu=-1; while(st<=dr) { int mij=(st+dr)/2; if(getmax(mij,B) < getmax(C,D)) { primu=unde[getmax(mij,B)]; dr=mij-1; } else { st=mij+1; } } /**for(int i=A;i<=B;i++) { if(getmax(i,B) < getmax(C,D)) { primu=unde[getmax(i,B)]; break; } }*/ if(primu==-1) return -1; else return getdist(primu,C,D); }
#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...