이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |