#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"
const int maxn = 200005;
pair<int, int> adj[maxn]; //left, right
int dist[maxn];
void init(int N, vector<int> H){
for (int i=0; i<=N; i++) dist[i] = INT_MAX;
stack<int> tree;
for(int i=0; i<N; i++){
while(!tree.empty() && H[tree.top()]<H[i]) tree.pop();
if(!tree.empty()) adj[i].first = tree.top();
else adj[i].first = -1;
tree.push(i);
}
while(!tree.empty()) tree.pop();
for(int i=N-1; i>=0; i--){
while(!tree.empty() && H[tree.top()]<H[i]) tree.pop();
if(!tree.empty()) adj[i].second = tree.top();
else adj[i].second = -1;
tree.push(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(i!=-1 && dist[i]>dist[v]+1){
dist[i] = dist[v]+1;
q.push(i);
}
int j = adj[v].second;
if(j!=-1 && dist[j]>dist[v]+1){
dist[j] = dist[v]+1;
q.push(j);
}
}
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2392 KB |
Output is correct |
3 |
Incorrect |
2033 ms |
4388 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
0 ms |
2392 KB |
Output is correct |
5 |
Correct |
20 ms |
3880 KB |
Output is correct |
6 |
Correct |
22 ms |
4280 KB |
Output is correct |
7 |
Correct |
10 ms |
3404 KB |
Output is correct |
8 |
Incorrect |
27 ms |
4276 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2388 KB |
Output is correct |
4 |
Incorrect |
133 ms |
3368 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2388 KB |
Output is correct |
4 |
Incorrect |
133 ms |
3368 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2392 KB |
Output is correct |
3 |
Incorrect |
2033 ms |
4388 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |