이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "jumps.h"
#include <vector>
#include <queue>
using namespace std;
vector<vector<int>> G(200100);
int n;
struct SEG{
private:
int n;
vector<int> node;
public:
SEG(int N){
n = 1;
while(n < N) n *= 2;
node.resize(2*n-1,0);
}
void update(int i, int x){
i += n-1;
node[i] = x;
while(i > 0){
i--;
i /= 2;
node[i] = max(node[2*i+1],node[2*i+2]);
}
return;
}
int query(int a, int b, int k = 0, int l = 0, int r = -1){
if(r < 0) r = n;
if(a >= b) return 0;
if(b <= l || r <= a) return 0;
if(a <= l && r <= b) return node[k];
int vl = query(a,b,2*k+1,l,(l+r)/2);
int vr = query(a,b,2*k+2,(l+r)/2,r);
return max(vl,vr);
}
};
SEG seg(200100);
void init(int N, std::vector<int> H) {
n = N;
for(int i=0;i<N;i++) seg.update(i,H[i]);
for(int i=0;i<N;i++){
if(seg.query(0,i) > H[i]){
int ac = 0, wa = i;
while(wa-ac > 1){
int wj = (ac+wa)/2;
if(seg.query(wj,i) > H[i]) ac = wj;
else wa = wj;
}
G[i].push_back(ac);
}
if(seg.query(i+1,N) > H[i]){
int ac = N, wa = i;
while(ac-wa > 1){
int wj = (ac+wa)/2;
if(seg.query(i+1,wj) > H[i]) ac = wj;
else wa = wj;
}
G[i].push_back(wa);
}
}
return;
}
int minimum_jumps(int A, int B, int C, int D) {
vector<int> dist(n,1e9);
queue<int> q;
for(int i=A;i<=B;i++){
dist[i] = 0;
q.push(i);
}
while(!q.empty()){
int pos = q.front();
q.pop();
for(int x:G[pos]){
if(dist[x] != 1e9) continue;
dist[x] = dist[pos] + 1;
q.push(x);
}
}
int ans = 1e9;
for(int i=C;i<=D;i++) ans = min(ans,dist[i]);
return (ans == 1e9 ? -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... |