# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
552409 | cig32 | 밀림 점프 (APIO21_jumps) | C++17 | 997 ms | 34760 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "jumps.h"
#include <stack>
#include <vector>
#include <iostream>
#include <queue>
const int MAXN = 200010;
int L[MAXN], R[MAXN];
int N_;
int mi[19][MAXN], ma[19][MAXN];
int V[MAXN];
void init(int N, std::vector<int> H) {
N_ = N;
for(int i=0; i<N; i++) {
L[i] = R[i] = -1;
V[i] = H[i];
}
std::stack<int> st;
for(int i=0; i<N; i++) {
while(st.size() && H[st.top()] < H[i]) {
st.pop();
}
if(st.size()) L[i] = st.top();
st.push(i);
}
while(st.size()) st.pop();
for(int i=N-1; i>=0; i--) {
while(st.size() && H[st.top()] < H[i]) {
st.pop();
}
if(st.size()) R[i] = st.top();
st.push(i);
}
while(st.size()) st.pop();
for(int i=0; i<N; i++) {
if(L[i] == -1 && R[i] == -1) {
mi[0][i] = ma[0][i] = -1;
}
else if(L[i] == -1) {
mi[0][i] = ma[0][i] = R[i];
}
else if(R[i] == -1) {
mi[0][i] = ma[0][i] = L[i];
}
else {
mi[0][i] = (H[L[i]] < H[R[i]] ? L[i] : R[i]);
ma[0][i] = (H[L[i]] > H[R[i]] ? L[i] : R[i]);
}
}
for(int i=1; i<19; i++) {
for(int j=0; j<N; j++) {
if(mi[i-1][j] == -1) mi[i][j] = -1;
else mi[i][j] = mi[i-1][mi[i-1][j]];
if(ma[i-1][j] == -1) ma[i][j] = -1;
else ma[i][j] = ma[i-1][ma[i-1][j]];
}
}
}
int minimum_jumps(int A, int B, int C, int D) {
int N = N_;
int ans = 0;
// A = B, C = D
for(int i=18; i>=0; i--) {
if(ma[i][A] != -1) {
if(V[ma[i][A]] <= V[C]) {
A = ma[i][A];
ans += (1 << i);
}
}
}
for(int i=18; i>=0; i--) {
if(mi[i][A] != -1) {
if(V[mi[i][A]] <= V[C]) {
A = mi[i][A];
ans += (1 << i);
}
}
}
return (A == C ? ans : -1);
}
/*
Compilation:
./compile_sh
./jumps
*/
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |