이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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");
}
컴파일 시 표준 에러 (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... |