이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<stdio.h>
const int LM=(int)1e5+5;
bool used[4][LM];
int a,b,c,d;
struct State{
int L,R,S;
}que[LM*4];
int fr,re;
int push(int L,int R,int S){
int i,j;
if(L>=a)R+=L-a,L=a,i=1,j=R;
else if(R>=b)L+=R-b,R=b,i=3,j=L;
else if(L==0)i=0,j=R;
else if(R==0)i=2,j=L;
if(used[i][j])return 0;
if(L==c&&R==d)return 1;
used[i][j]=1;
que[re++]={L,R,S};
return 0;
}
int bfs(){
push(0,0,0);
if(c==0&&d==0)return 0;
while(fr<re){
State&t=que[fr++];
if(push(0,t.R,t.S+1))return t.S+1;
if(push(0,t.L+t.R,t.S+1))return t.S+1;
if(push(a,t.R,t.S+1))return t.S+1;
if(push(t.L,0,t.S+1))return t.S+1;
if(push(t.L+t.R,0,t.S+1))return t.S+1;
if(push(t.L,b,t.S+1))return t.S+1;
}
return -1;
}
int main(){
scanf("%d%d%d%d",&a,&b,&c,&d);
printf("%d",bfs());
}
컴파일 시 표준 에러 (stderr) 메시지
bucket.cpp: In function 'int main()':
bucket.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d",&a,&b,&c,&d);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bucket.cpp: In function 'int push(int, int, int)':
bucket.cpp:17:17: warning: 'j' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(used[i][j])return 0;
~~~~~~~~~^
bucket.cpp:17:17: warning: 'i' may be used uninitialized in this function [-Wmaybe-uninitialized]
# | 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... |