이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "jumps.h"
using namespace std;
#include<bits/stdc++.h>
#define pb push_back
int n,m,l,r,i,j,ii,jj,k,h[20][200002];
vector<int> v[200006];
int asuu(int l, int r){
int k=r-l+1;
k = 31 - __builtin_clz(k);
return max(h[l][k],h[r-(1<<k)+1][k]);
}
void init(int N, std::vector<int> H){
n=N;
for(i=0;i<n;i++) h[0][i]=H[i];
for(j=1;j<=20;j++)
for(i=0;i<n;i++){
l=h[j-1][i];
if(i+(1<<(j-1))) h[j][i]=max(l,h[j-1][i+(1<<(j-1))]);
}
for(i=0;i<n;i++){
if(i!=0 && asuu(0,i-1)>H[i]){
l=0;
r=i-1;
while(r-l>1){
m=(r+l)/2;
if(asuu(m+1,r)>H[i]) l=m+1;
else r=m;
}
if(H[r]>H[i]) k=r;
else k=l;
v[i].pb(k);
}
if(i!=n-1 && asuu(i+1,n-1) > H[i]){
l=i+1;
r=n-1;
while(r-l>1){
m=(r+l)/2;
if(asuu(l,m)>H[i]) r=m;
else l=m+1;
}
if(H[l]>H[i]) k=l;
else k=r;
v[i].pb(k);
}
}
}
int minimum_jumps(int A, int B, int C, int D) {
int dist[200005];
queue<int> q;
memset(dist,-1,sizeof(dist));
for(i=A;i<=B;i++){
q.push(i);
dist[i]=0;
}
while(!q.empty()){
int node= q.front();
q.pop();
for(i=0;i<v[node].size();i++)
if(dist[v[node][i]]==-1){
dist[v[node][i]]=dist[node]+1;
if(v[node][i]>=C && v[node][i]<=D) return dist[v[node][i]];
q.push(v[node][i]);
}
}
return -1;
}
컴파일 시 표준 에러 (stderr) 메시지
jumps.cpp: In function 'int minimum_jumps(int, int, int, int)':
jumps.cpp:59:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(i=0;i<v[node].size();i++)
| ~^~~~~~~~~~~~~~~
# | 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... |