이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "jumps.h"
//#include "stub.cpp"
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
#define all(x) x.begin(),x.end()
#define pb push_back
vvi g;
int n=-1;
bool line=1;
void init(int N, vi h){
n=N;
g.resize(n);
for(int i=0; i<n; i++)
line&=h[i]==i+1;
vi nxt(n,-1),prv(n,-1);
stack<int>s;
for(int i=0; i<n; i++){
while(s.size() && h[i]>h[s.top()]){
nxt[s.top()]=i;
s.pop();
}
s.push(i);
}
while(s.size())
s.pop();
for(int i=n-1; 0<=i ;i--){
while(s.size() && h[i]>h[s.top()]){
prv[s.top()]=i;
s.pop();
}
s.push(i);
}
for(int i=0; i<n;i ++){
if(nxt[i]!=-1)
g[i].pb(nxt[i]);
if(prv[i]!=-1)
g[i].pb(prv[i]);
}
}
int minimum_jumps(int A, int B, int C, int D){
if(line)
return C-B;
vector<bool>vis(n);
queue<pi>q;
for(int i=A; i<=B; i++)
q.push({0,i});
while(q.size()){
pi cur=q.front();
q.pop();
int src=cur.second,dst=cur.first;
if(C<= src && src<=D)
return dst;
if(vis[src])continue;
vis[src]=1;
for(int nbr:g[src])
if(!vis[nbr])
q.push({dst+1,nbr});
}
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... |