이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
int n,dist[200005], p1[200005][20], p2[200005][20], X[200005];
vector<int> lst[200005];
stack<int> s;
queue<int> q;
void init(int N, std::vector<int> H) {
n = N;
for (int i = 0; i < N; ++i) X[i] = H[i];
memset(p1,-1,sizeof(p1));
memset(p2,-1,sizeof(p2));
for (int i = 0; i < N; ++i) {
while (!s.empty() && H[i] >= H[s.top()]) s.pop();
if (!s.empty()) p1[i][0] = s.top();
s.push(i);
}
while (!s.empty()) s.pop();
for (int i = N-1; i >= 0; --i) {
while (!s.empty() && H[i] >= H[s.top()]) s.pop();
if (!s.empty()) p2[i][0] = s.top();
s.push(i);
}
for (int i = 0; i < N; ++i) if (p1[i][0] == -1 || (p1[i][0] != -1 && p2[i][0] != -1 && H[p1[i][0]] < H[p2[i][0]])) swap(p1[i][0], p2[i][0]);
for (int k = 1; k < 20; ++k) for (int i = 0; i < N; ++i) {
if (p1[i][k-1] == -1) p1[i][k] = -1;
else p1[i][k] = p1[p1[i][k-1]][k-1];
if (p2[i][k-1] == -1) p2[i][k] = -1;
else p2[i][k] = p2[p2[i][k-1]][k-1];
}
}
int minimum_jumps(int A, int B, int C, int D) {
int ans = 0;
for (int k = 19; k >= 0; --k) if (p1[A][k] != -1 && X[p1[A][k]] <= X[C]) ans += (1<<k), A = p1[A][k];
for (int k = 19; k >= 0; --k) if (p2[A][k] != -1 && X[p2[A][k]] <= X[C]) ans += (1<<k), A = p2[A][k];
if (A != C) return -1;
else 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... |