#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e5;
int A, B, C, D;
struct Queue { int x, y, val; };
queue<Queue> Q;
map<pii, int> vis;
void enque(int x, int y, int val)
{
if(vis.count({x, y})) return;
vis[{x, y}]=val;
Q.push({x, y, val});
}
int main()
{
int i, j;
scanf("%d%d%d%d", &A, &B, &C, &D);
enque(0, 0, 0);
while(!Q.empty())
{
Queue now=Q.front(); Q.pop();
enque(A, now.y, now.val+1);
enque(now.x, B, now.val+1);
enque(0, now.y, now.val+1);
enque(now.x, 0, now.val+1);
enque(now.x+now.y-min(now.y+now.x, B), min(now.y+now.x, B), now.val+1);
enque(min(now.x+now.y, A), now.x+now.y-min(now.x+now.y, A), now.val+1);
}
if(vis.count({C, D})) printf("%d", vis[{C, D}]);
else printf("-1");
}
Compilation message
bucket.cpp: In function 'int main()':
bucket.cpp:26:9: warning: unused variable 'i' [-Wunused-variable]
int i, j;
^
bucket.cpp:26:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
bucket.cpp:28: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);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
12 ms |
1144 KB |
Output is correct |
7 |
Correct |
66 ms |
3924 KB |
Output is correct |
8 |
Correct |
280 ms |
12956 KB |
Output is correct |
9 |
Correct |
285 ms |
12776 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
12 ms |
1144 KB |
Output is correct |
7 |
Correct |
66 ms |
3924 KB |
Output is correct |
8 |
Correct |
280 ms |
12956 KB |
Output is correct |
9 |
Correct |
285 ms |
12776 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
2 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
256 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
424 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
504 KB |
Output is correct |
7 |
Correct |
3 ms |
504 KB |
Output is correct |
8 |
Correct |
5 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
12 ms |
1144 KB |
Output is correct |
7 |
Correct |
66 ms |
3924 KB |
Output is correct |
8 |
Correct |
280 ms |
12956 KB |
Output is correct |
9 |
Correct |
285 ms |
12776 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
2 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
256 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
424 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
3 ms |
504 KB |
Output is correct |
27 |
Correct |
3 ms |
504 KB |
Output is correct |
28 |
Correct |
5 ms |
504 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
14 ms |
1400 KB |
Output is correct |
32 |
Correct |
21 ms |
2040 KB |
Output is correct |
33 |
Correct |
205 ms |
12896 KB |
Output is correct |
34 |
Correct |
16 ms |
1528 KB |
Output is correct |
35 |
Correct |
8 ms |
888 KB |
Output is correct |
36 |
Correct |
4 ms |
504 KB |
Output is correct |
37 |
Correct |
15 ms |
1412 KB |
Output is correct |
38 |
Correct |
23 ms |
1748 KB |
Output is correct |
39 |
Correct |
17 ms |
1656 KB |
Output is correct |
40 |
Correct |
8 ms |
1016 KB |
Output is correct |
41 |
Correct |
50 ms |
4088 KB |
Output is correct |
42 |
Correct |
60 ms |
5112 KB |
Output is correct |
43 |
Correct |
29 ms |
2680 KB |
Output is correct |
44 |
Correct |
20 ms |
1836 KB |
Output is correct |
45 |
Correct |
692 ms |
25344 KB |
Output is correct |
46 |
Correct |
2 ms |
256 KB |
Output is correct |