# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
85545 |
2018-11-20T21:51:30 Z |
kjh5678 |
None (KOI17_bucket) |
C++14 |
|
3 ms |
1036 KB |
#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
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 |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
492 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Runtime error |
2 ms |
604 KB |
Execution failed because the return code was nonzero |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
492 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Runtime error |
2 ms |
604 KB |
Execution failed because the return code was nonzero |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
636 KB |
Output is correct |
2 |
Correct |
2 ms |
700 KB |
Output is correct |
3 |
Correct |
2 ms |
704 KB |
Output is correct |
4 |
Correct |
2 ms |
708 KB |
Output is correct |
5 |
Correct |
3 ms |
728 KB |
Output is correct |
6 |
Correct |
2 ms |
772 KB |
Output is correct |
7 |
Correct |
2 ms |
776 KB |
Output is correct |
8 |
Correct |
2 ms |
1036 KB |
Output is correct |
9 |
Correct |
2 ms |
1036 KB |
Output is correct |
10 |
Correct |
2 ms |
1036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
492 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Runtime error |
2 ms |
604 KB |
Execution failed because the return code was nonzero |
6 |
Halted |
0 ms |
0 KB |
- |