이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, L[maxn][20], R[maxn][20];
vector<int> v;
void init(int N, vector<int> H) {
n = N;
v.push_back(1e9);
for(int &x : H) v.push_back(x);
v.push_back(1e9);
stack<pair<int, int> > st; st.push({ 1e9, 0 });
for(int i=1; i<=n; i++) {
while(!st.empty() && st.top().first <= v[i]) st.pop();
L[i][0] = st.top().second;
st.push({ v[i], i });
}
while(!st.empty()) st.pop();
st.push({ 1e9, n + 1 });
for(int i=n; i>=1; i--) {
while(!st.empty() && st.top().first <= v[i]) st.pop();
R[i][0] = st.top().second;
st.push({ v[i], i });
}
}
int minimum_jumps(int A, int B, int C, int D) {
A++; B++; C++; D++;
vector<int> dist(n+1), vis(n+1);
queue<int> q;
for(int i=A; i<=B; i++) vis[i] = 1, q.push(i);
while(!q.empty()) {
int u = q.front();
q.pop();
if(C <= u && u <= D) return dist[u];
if(L[u][0] != 0 && !vis[L[u][0]]) {
vis[L[u][0]] = 1;
dist[L[u][0]] = dist[u] + 1;
q.push(L[u][0]);
}
if(R[u][0] != n + 1 && !vis[R[u][0]]) {
vis[R[u][0]] = 1;
dist[R[u][0]] = dist[u] + 1;
q.push(R[u][0]);
}
}
return -1;
}
# | 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... |