이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int dist[200002];
int l[200002], r[200002];
vector<pair<int, int>> v;
int N; bool st1 = true;
void init(int N_tmp, vector<int> H) {
N = N_tmp;
for(int i = 0; i < N; i++){
v.push_back({H[i], i + 1});
if(H[i] != i + 1) st1 = false;
}
sort(v.begin(), v.end(), greater<pair<int, int>>());
set<pair<int, int>> v2;
for(auto [x, tmp] : v){
if(v2.empty()){
v2.insert({tmp, x});
continue;
}
auto it = v2.lower_bound({tmp, 0});
// printf(">> %d %d : %d %d\n", x, tmp, (*it).first, (*it).second);
if(it != v2.end()) r[x] = (*it).second;
if(it != v2.begin()){
it--;
l[x] = (*it).second;
}
v2.insert({tmp, x});
}
}
int minimum_jumps(int A, int B, int C, int D) {
if(st1) return C - B;
int ans = 1000000000; A++; B++; C++; D++;
for(int i = 0; i <= N; i++) dist[i] = 1000000000;
for(auto [x, idx]: v){
if(idx >= C && idx <= D) dist[x] = 0;
if(idx >= A && idx <= B) ans = min({ans, dist[l[x]] + 1, dist[r[x]] + 1});
dist[x] = min({dist[x], dist[l[x]] + 1, dist[r[x]] + 1});
// printf(">> %d (%d, %d) : %d %d\n", x, l[x], r[x], dist[l[x]], dist[r[x]]);
}
return ans == 1000000000 ? -1 : 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... |