#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
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);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
256 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
256 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
256 KB |
Output is correct |
2 |
Runtime error |
5 ms |
380 KB |
Execution failed because the return code was nonzero |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
256 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |