#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define nl "\n"
int n;
vector<int> h;
const int maxn = 200005;
pair<int, int> adj[maxn]; //left, right
int dist[maxn];
void init(int N, vector<int> H){
n = N;
h = H;
stack<int> tree;
for(int i=0; i<n; i++){
while(!tree.empty() && tree.top()<h[i]) tree.pop();
if(!tree.empty()) adj[i].first = tree.top();
else adj[i].first = -1;
tree.push(h[i]);
}
while(!tree.empty()) tree.pop();
for(int i=n-1; i>=0; i--){
while(!tree.empty() && tree.top()<h[i]) tree.pop();
if(!tree.empty()) adj[i].second = tree.top();
else adj[i].second = -1;
tree.push(h[i]);
}
}
int minimum_jumps(int A, int B, int C, int D){
queue<int> q;
for (int i=A; i<=B; i++) {
q.push(i);
dist[i] = 0;
}
while(!q.empty()){
int v = q.front();
q.pop();
if(C<=v && v<=D){
return dist[v];
}
int i = adj[v].first;
if(dist[i]>dist[v]+1){
dist[i] = dist[v]+1;
q.push(i);
}
int j = adj[v].second;
if(dist[j]>dist[v]+1){
dist[j] = dist[v]+1;
q.push(j);
}
}
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |