이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "jumps.h"
#include <bits/stdc++.h>
#include <vector>
using namespace std;
const int maxn = 1e5 + 10;
int n,d[maxn];
int a[maxn];
vector <int> adj[maxn];
void addedge(int u, int v)
{
adj[u].push_back(v);
}
void init(int N, std::vector<int> H) {
n=N;
for (int i=0; i<n; i++) a[i]=H[i],adj[i].clear();
deque<int> dq;
for (int i=0; i<n; i++)
{
while (!dq.empty()&&a[dq.back()] < a[i]) dq.pop_back();
if (!dq.empty()) addedge(i,dq.back());
dq.push_back(i);
}
while (!dq.empty()) dq.pop_back();
for (int i=n-1; i>=0; i--)
{
while (!dq.empty()&&a[dq.back()] < a[i]) dq.pop_back();
if (!dq.empty()) addedge(i,dq.back());
dq.push_back(i);
}
}
int minimum_jumps(int A, int B, int C, int D) {
queue<int> q;
fill_n(d,n,-1);
// for (int i=0; i<n; i++)
// {
//// cerr<<i<<" : ";
//// for (int j:adj[i]) cerr<<j<<' '; cerr<<endl;
// }
for (int i=A; i<=B; i++)
{
d[i]=0;
q.push(i);
}
while (!q.empty())
{
int u=q.front(); q.pop();
// cerr<<u<<endl;
for (int v:adj[u])
if (d[v]==-1)
{
// cerr<<u<<" - "<<v<<endl;
d[v]=d[u]+1;
q.push(v);
}
}
int ans=1e9;
for (int i=C; i<=D; i++) if (d[i]!=-1) ans=min(ans,d[i]);
if (ans==1e9) ans=-1;
return ans;
}
# | 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... |