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>
#include <queue>
#include <map>
#include <algorithm>
#include <stdlib.h>
#define min2(x,y) (x<y?x:y)
using namespace std;
map<pair<int,int>,bool> check;
queue<pair<pair<int,int>,int> > Q;
int A, B, MA, MB, lev;
void Push(int x, int y){
if(!check[{x,y}]){
check[{x,y}]=true, Q.push({{x,y},lev+1});
if(x==MA && y==MB) printf("%d",lev+1), exit(true);
}
}
int main(){
pair<int,int> x;
scanf("%d %d %d %d",&A,&B,&MA,&MB);
check[{0,0}]=true, Q.push({{0,0},0});
if(MA==0 && MB==0){ printf("0"); return 0; }
while(!Q.empty()){
x=Q.front().first, lev=Q.front().second, Q.pop();
Push(0,x.second), Push(x.first,0);
Push(A,x.second), Push(x.first,B);
Push(x.first-min2(x.first,B-x.second),x.second+min2(x.first,B-x.second));
Push(x.first+min2(x.second,A-x.first),x.second-min2(x.second,A-x.first));
}
printf("-1");
}
Compilation message (stderr)
bucket.cpp: In function 'int main()':
bucket.cpp:22: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,&MA,&MB);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |