이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<long long, long long>
#define fr first
#define se second
int n;
vector<int> h;
vector<int> l;
vector<int> r;
void init(int32_t N, vector<int32_t> H) {
n = N;
h.resize(n);
for (int i = 0; i < n; i++) h[i] = H[i];
l.resize(n);
r.resize(n);
stack<pii> s;
for (int i = 0; i < n; i++) {
while (!s.empty() && (s.top().fr < h[i])) s.pop();
if (s.empty()) l[i] = -1;
else l[i] = s.top().se;
s.push({h[i], i});
}
while (!s.empty()) s.pop();
for (int i = n - 1; i >= 0; i--) {
while (!s.empty() && (s.top().fr < h[i])) s.pop();
if (s.empty()) r[i] = -1;
else r[i] = s.top().se;
s.push({h[i], i});
}
//for (int i = 0; i < n; i++) cout << l[i] << " " << r[i] << "\n";
return;
}
const int INF = 0x3f3f3f3f;
vector<int> dist;
int calc(int node) {
//cout << "node " << node << "\n";
if (node == -1) return INF;
if (dist[node] != INF) return dist[node];
dist[node] = min(calc(l[node]) + 1, calc(r[node]) + 1);
return dist[node];
}
int32_t minimum_jumps(int32_t A, int32_t B, int32_t C, int32_t D) {
dist.clear();
dist.resize(n, INF);
for (int i = C; i <= D; i++) dist[i] = 0;
int ans = INF;
for (int i = A; i <= B; i++) {
ans = min(ans, calc(i));
}
if (ans == INF) 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... |