This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#if 01
#include <stdio.h>
int a, b, c, d;
typedef struct st
{
int curx;
int cury;
int cnt;
st* next;
st* prev;
st(){ curx = cury = cnt = 0; next = prev = (st*)0; }
st(int a, int b, int c, st* d, st* e){ curx = a; cury = b; cnt = c; next = d; prev = e; }
}q;
q* head;
q* tail;
int cur[100001][4];
int empty()
{
if (head->next == tail) return 1;
else return 0;
}
void enq(int x,int y,int c)
{
q* temp = tail->prev;
tail->prev = new q(x, y, c, tail, temp);
temp->next = tail->prev;
}
q* deq()
{
if (empty()) return 0;
q* temp = head->next;
head->next->next->prev = head;
head->next = head->next->next;
return temp;
}
int BFS()
{
q* out;
enq(0, 0, 0);
cur[0][1] = -1;
cur[0][2] = -1;
while (!empty())
{
out = deq();
if (out->curx==c&&out->cury==d)
{
return out->cnt;
}
if (!cur[out->cury][0])
{
cur[out->cury][0] = out->cnt + 1;
enq(a, out->cury, out->cnt + 1);
}
if (!cur[out->cury][1])
{
cur[out->cury][1] = out->cnt + 1;
enq(0, out->cury, out->cnt + 1);
}
if (!cur[out->curx][2])
{
cur[out->curx][2] = out->cnt + 1;
enq(out->curx, 0, out->cnt + 1);
}
if (!cur[out->curx][3])
{
cur[out->curx][3] = out->cnt + 1;
enq(out->curx, b, out->cnt + 1);
}
if (b - out->cury >= out->curx)
{
if (!cur[out->curx + out->cury][1])
{
cur[out->curx + out->cury][1] = out->cnt + 1;
enq(0, out->curx + out->cury, out->cnt + 1);
}
}
else
{
if (!cur[out->curx - (b - out->cury)][3])
{
cur[out->curx - (b - out->cury)][3] = out->cnt + 1;
enq(out->curx - (b - out->cury), b, out->cnt + 1);
}
}
if (a - out->curx >= out->cury)
{
if (!cur[out->curx + out->cury][2])
{
cur[out->curx + out->cury][2] = out->cnt + 1;
enq(out->curx + out->cury, 0, out->cnt + 1);
}
}
else
{
if (!cur[out->cury - (a - out->curx)][0])
{
cur[out->cury - (a - out->curx)][0] = out->cnt + 1;
enq(a, out->cury - (a - out->curx), out->cnt + 1);
}
}
}
return 0;
}
int main(void)
{
scanf("%d%d%d%d", &a, &b, &c, &d);
if (c == 0 && d == 0){
printf("0"); return 1;
}
head = new q();
tail = new q();
head->next = tail;
tail->prev = head;
int ans = BFS();
if (ans) printf("%d\n", ans);
else printf("-1");
}
#endif
Compilation message (stderr)
bucket.cpp: In function 'int main()':
bucket.cpp:118:7: 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... |