이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
int n;
int X[200005], Y[200005];
void init(int N, vector<int> H){
n = N;
stack<int>s;
for(int i=0;i<n;i++){
while(!s.empty() && H[s.top()] < H[i])s.pop();
X[i] = (s.empty() ? -1 : s.top());
s.push(i);
}
while(!s.empty())s.pop();
for(int i=n-1;i>=0;i--){
while(!s.empty() && H[s.top()] < H[i])s.pop();
X[i] = (s.empty() ? -1 : s.top());
s.push(i);
}
}
int minimum_jumps(int a, int b, int c, int d){
queue<int>q;
int dist[n+1];
for(int i=0;i<n;i++)dist[i] = 1e9;
for(int i=a;i<=b;i++)dist[i] = 0, q.push(i);
while(!q.empty()){
int x = q.front();q.pop();
if(X[x] != -1 && dist[X[x]] > dist[x] + 1)dist[X[x]] = dist[x] + 1, q.push(X[x]);
if(Y[x] != -1 && dist[Y[x]] > dist[x] + 1)dist[Y[x]] = dist[x] + 1, q.push(Y[x]);
}
int mini = 1e9;
for(int i=c;i<=d;i++)mini = min(mini, dist[i]);
return mini;
}
# | 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... |