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 <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 (stderr)
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);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |