Submission #1062960

#TimeUsernameProblemLanguageResultExecution timeMemory
1062960vjudge1Rainforest Jumps (APIO21_jumps)C++17
0 / 100
4017 ms31984 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 leftist(int B, int C, int D) { 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; } int minimum_jumps(int A, int B, int C, int D) { int sol = -1; for(int i = A; i <= B; i++) { int r = leftist(i, C, D); if(r != -1) sol = (sol == -1? r : min(sol, r)); } return sol; //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; //} } /** 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...