이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 1;
vector<int> firstGreaterToTheRight;
vector<vector<int>> adj;
void init(int N, vector<int> H)
{
stack<pair<int, int>> s;
firstGreaterToTheRight = vector<int>(N, -1);
adj = vector<vector<int>>(N);
for (int i = N - 1; i >= 0; i--)
{
while (!s.empty() && s.top().first < H[i])
s.pop();
if (!s.empty())
firstGreaterToTheRight[i] = s.top().second;
s.push({H[i], i});
}
for (int i = 0; i < N; i++)
if (firstGreaterToTheRight[i] != -1)
adj[i].push_back(firstGreaterToTheRight[i]);
}
int minimum_jumps(int A, int B, int C, int D)
{
int res = INF;
queue<pair<int, int>> bfs;
map<int, bool> vis;
for (int L = A; L <= B; L++)
{
bfs.push({L, 0});
vis[L] = true;
}
while (!bfs.empty())
{
pair<int, int> cur = bfs.front();
bfs.pop();
for (int a : adj[cur.first])
{
if (vis[a])
continue;
vis[a] = true;
bfs.push({a, cur.second + 1});
if (C <= a && a <= D)
res = min(res, cur.second + 1);
}
}
return (res == INF ? -1 : res);
}
# | 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... |