제출 #1062958

#제출 시각아이디문제언어결과실행 시간메모리
1062958vjudge1밀림 점프 (APIO21_jumps)C++17
4 / 100
791 ms31816 KiB
#include <bits/stdc++.h> #define all(x) (x).begin(),(x).end() using namespace std; using ll = long long; using ld = long double; //#define int ll #define sz(x) ((int)(x).size()) using pii = pair<int,int>; using tii = tuple<int,int,int>; const int nmax = 2e5 + 5; int toright[nmax][18], toleft[nmax][18]; int N; void init(int N_, std::vector<int> H) { N = N_; vector<int> st; H.emplace_back(1e9 + 5); st.emplace_back(N); toleft[N][0] = N; for(int i = 0; i < N; i++) { while(H[st.back()] < H[i]) st.pop_back(); toleft[i][0] = st.back(); st.emplace_back(i); } for(int step = 1; step < 18; step++) for(int i = 0; i <= N; i++) toleft[i][step] = toleft[toleft[i][step - 1]][step - 1]; st.clear(); st.emplace_back(N); for(int i = N - 1; i >= 0; i--) { while(H[st.back()] < H[i]) st.pop_back(); toright[i][0] = st.back(); st.emplace_back(i); } toright[N][0] = N; for(int step = 1; step < 18; step++) for(int i = 0; i <= N; i++) toright[i][step] = toright[toright[i][step - 1]][step - 1]; } int minimum_jumps(int A, int B, int C, int D) { for(int i = 17; i >= 0; i--) { int cand = toleft[B][i]; if(cand == N) continue; if(cand < A) continue; if(toright[cand][0] > D) continue; if(toright[cand][0] >= C) return 1; B = cand; } int cnt = 0; for(int i = 17; i >= 0; i--) { int cand = toright[B][i]; if(cand >= C) continue; B = cand; cnt += (1 << i); } if(toright[B][0] > D) return -1; return cnt + 1; } /** Töte es durch genaue Untersuchung\Töte es kann es nur noch schlimmer machen\Es lässt es irgendwie atmen -- */
#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...