# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
112694 | arnold518 | 물통 (KOI17_bucket) | C++14 | 597 ms | 25456 KiB |
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, v; };
map<pii, int> vis;
queue<Queue> Q;
void enque(Queue p)
{
if(vis.count({p.x, p.y})) return;
vis[{p.x, p.y}]=p.v;
Q.push(p);
}
int main()
{
int i, j;
scanf("%d%d%d%d", &a, &b, &c, &d);
Q.push({0, 0, 0}); vis[{0, 0}];
while(!Q.empty())
{
Queue now=Q.front();
Q.pop();
int s=now.x+now.y;
Queue nxt; nxt.v=now.v+1;
nxt.y=min(s, b); nxt.x=s-nxt.y;
enque(nxt);
nxt.x=min(s, a); nxt.y=s-nxt.x;
enque(nxt);
nxt.x=a; nxt.y=now.y;
enque(nxt);
nxt.x=now.x; nxt.y=b;
enque(nxt);
nxt.x=0; nxt.y=now.y;
enque(nxt);
nxt.x=now.x; nxt.y=0;
enque(nxt);
}
if(vis.count({c, d})) printf("%d", vis[{c, d}]);
else printf("-1");
}
Compilation message (stderr)
# | 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... |