이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "jumps.h"
using namespace std;
using ll = long long;
#define MAXN (1000005)
ll N;
bool subtask1 = 1;
vector<ll> v[MAXN];
void init(int n, vector<int> H){
N = n;
for(ll i = 0;i < N;i++){
if(H[i] != i + 1){
subtask1 = 0;
}
}
stack<ll> s;
for(ll i = 0;i < N;i++){
while(!s.empty() && H[s.top()] < H[i]){
s.pop();
}
if(!s.empty()){
v[i].push_back(s.top());
}
s.push(i);
}
while(!s.empty()){
s.pop();
}
for(ll i = N - 1;i >= 0;i--){
while(!s.empty() && H[s.top()] < H[i]){
s.pop();
}
if(!s.empty()){
v[i].push_back(s.top());
}
s.push(i);
}
}
int minimum_jumps(int A, int B, int C, int D){
if(subtask1){
return C - B;
}
queue<ll> q;
ll dist[N];
memset(dist,-1,sizeof(dist));
for(ll i = A;i <= B;i++){
q.push(i);
dist[i] = 0;
}
while(!q.empty()){
ll x = q.front();
q.pop();
for(auto u : v[x]){
if(dist[u] == -1){
q.push(u);
dist[u] = dist[x] + 1;
}
}
}
ll mini = 1e18;
for(ll i = C;i <= D;i++){
if(dist[i] == -1) continue;
mini = min(mini,dist[i]);
}
if(mini == 1e18) return -1;
else 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... |