This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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());
}
Compilation message (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... |