답안 #85546

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
85546 2018-11-20T21:52:12 Z kjh5678 물통 (KOI17_bucket) C++14
100 / 100
32 ms 20280 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 0;
	}
	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);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 496 KB Output is correct
3 Correct 2 ms 540 KB Output is correct
4 Correct 2 ms 540 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 676 KB Output is correct
7 Correct 5 ms 2780 KB Output is correct
8 Correct 2 ms 2780 KB Output is correct
9 Correct 2 ms 2780 KB Output is correct
10 Correct 2 ms 2780 KB Output is correct
11 Correct 2 ms 2780 KB Output is correct
12 Correct 2 ms 2780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 496 KB Output is correct
3 Correct 2 ms 540 KB Output is correct
4 Correct 2 ms 540 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 676 KB Output is correct
7 Correct 5 ms 2780 KB Output is correct
8 Correct 2 ms 2780 KB Output is correct
9 Correct 2 ms 2780 KB Output is correct
10 Correct 2 ms 2780 KB Output is correct
11 Correct 2 ms 2780 KB Output is correct
12 Correct 2 ms 2780 KB Output is correct
13 Correct 2 ms 2780 KB Output is correct
14 Correct 2 ms 2780 KB Output is correct
15 Correct 2 ms 2780 KB Output is correct
16 Correct 2 ms 2780 KB Output is correct
17 Correct 2 ms 2780 KB Output is correct
18 Correct 2 ms 2780 KB Output is correct
19 Correct 2 ms 2780 KB Output is correct
20 Correct 2 ms 2780 KB Output is correct
21 Correct 2 ms 2780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2780 KB Output is correct
2 Correct 2 ms 2780 KB Output is correct
3 Correct 2 ms 2780 KB Output is correct
4 Correct 2 ms 2780 KB Output is correct
5 Correct 2 ms 2780 KB Output is correct
6 Correct 2 ms 2780 KB Output is correct
7 Correct 2 ms 2780 KB Output is correct
8 Correct 2 ms 2780 KB Output is correct
9 Correct 2 ms 2780 KB Output is correct
10 Correct 2 ms 2780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 496 KB Output is correct
3 Correct 2 ms 540 KB Output is correct
4 Correct 2 ms 540 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 676 KB Output is correct
7 Correct 5 ms 2780 KB Output is correct
8 Correct 2 ms 2780 KB Output is correct
9 Correct 2 ms 2780 KB Output is correct
10 Correct 2 ms 2780 KB Output is correct
11 Correct 2 ms 2780 KB Output is correct
12 Correct 2 ms 2780 KB Output is correct
13 Correct 2 ms 2780 KB Output is correct
14 Correct 2 ms 2780 KB Output is correct
15 Correct 2 ms 2780 KB Output is correct
16 Correct 2 ms 2780 KB Output is correct
17 Correct 2 ms 2780 KB Output is correct
18 Correct 2 ms 2780 KB Output is correct
19 Correct 2 ms 2780 KB Output is correct
20 Correct 2 ms 2780 KB Output is correct
21 Correct 2 ms 2780 KB Output is correct
22 Correct 2 ms 2780 KB Output is correct
23 Correct 2 ms 2780 KB Output is correct
24 Correct 2 ms 2780 KB Output is correct
25 Correct 2 ms 2780 KB Output is correct
26 Correct 2 ms 2780 KB Output is correct
27 Correct 2 ms 2780 KB Output is correct
28 Correct 2 ms 2780 KB Output is correct
29 Correct 2 ms 2780 KB Output is correct
30 Correct 2 ms 2780 KB Output is correct
31 Correct 2 ms 2780 KB Output is correct
32 Correct 2 ms 2780 KB Output is correct
33 Correct 29 ms 11656 KB Output is correct
34 Correct 2 ms 11656 KB Output is correct
35 Correct 3 ms 11656 KB Output is correct
36 Correct 2 ms 11656 KB Output is correct
37 Correct 2 ms 11656 KB Output is correct
38 Correct 4 ms 11656 KB Output is correct
39 Correct 3 ms 11656 KB Output is correct
40 Correct 3 ms 11656 KB Output is correct
41 Correct 4 ms 11656 KB Output is correct
42 Correct 8 ms 11656 KB Output is correct
43 Correct 5 ms 11656 KB Output is correct
44 Correct 5 ms 11656 KB Output is correct
45 Correct 32 ms 20280 KB Output is correct
46 Correct 2 ms 2780 KB Output is correct