이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = int; //long long;
using vi = vector<ll>;
using pl = pair<ll,ll>;
#define pb push_back
#define form(m,it) for(auto it=m.begin(); it!=m.end(); it++)
#define forp(i,a,b) for(ll i=a; i<=b; i++)
#define forn(i,a,b) for(ll i=a; i>=b; i--)
#define newl '\n'
#define ff first
#define ss second
const ll mod = 1e9 + 7;
ll n;
bool g=1;
ll h[200005];
vi adj[200005];
void init(ll N, vi he){
n = N;
forp(i,1,n){
h[i] = he[i-1];
}
stack<pl> st;
st.push({h[1],1});
forp(i,2,n){
while(!st.empty()&&st.top().ff<=h[i]){
st.pop();
}
if(st.size()>=1 && st.top().ff>h[i]){
adj[i].pb(st.top().ss);
}
st.push({h[i],i});
}
while(!st.empty()){st.pop();}
st.push({h[n],n});
forn(i,n-1,1){
while(!st.empty()&&st.top().ff<=h[i]){
st.pop();
}
if(st.size()>=1 && st.top().ff>h[i]){
adj[i].pb(st.top().ss);
}
st.push({h[i],i});
}
forp(i,1,n){
if(h[i]!=i)g=0;
}
}
int minimum_jumps(ll a, ll b, ll c, ll d){
if(g){
return c-b;
}
queue<pl> q;
bool vis[n+1] = {0};
a++; b++; c++; d++;
forp(i,a,b){
q.push({i,0});
vis[i]=1;
}
while(!q.empty()){
ll nd = q.front().ff; ll dis = q.front().ss; q.pop();
if(nd<=d && c<=nd){
return dis;
}
for(auto u:adj[nd]){
if(!vis[u]){
vis[u]=1;
q.push({u,dis+1});
}
}
}
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... |