Submission #4173


Source Code Expand

#include <stdio.h>
#include <stdlib.h>

#define A int
#define B int

typedef struct {
     A first;
     B second;
} pair;

int cmp_first(A a, A b)
{
     return a - b;
}

int cmp_second(B a, B b)
{
     return a - b;
}

int cmp_pair(pair a, pair b)
{
     int x = cmp_first(a.first, b.first);

     if (x != 0) return x;

     return cmp_second(a.second, b.second);
}

pair make_pair(A first, B second)
{
     pair p;

     p.first = first;
     p.second = second;

     return p;
}

#define Q pair

typedef struct _queue {
     Q value;
     int size;
     struct _queue *next;
     struct _queue *last;
} queue;

queue *push(queue *q, Q value)
{
     queue *tmp = malloc(sizeof(queue));

     tmp->value = value;
     tmp->next = NULL;
     tmp->last = tmp;

     if (q == NULL) {
	  tmp->size = 1;

	  return tmp;
     } else {
	  q->size++;

	  q->last->next = tmp;
	  q->last = tmp;

	  return q;
     }
}

queue *pop(queue *q)
{
     if (q->size == 1) {
	  free(q);

	  return NULL;
     } else {
	  queue *tmp = q->next;

	  tmp->size = q->size - 1;
	  tmp->last = q->last;

	  free(q);

	  return tmp;
     }
}

Q front(queue *q)
{
     return q->value;
}

int empty(queue *q)
{
     if (q == NULL) {
	  return 1;
     } else {
	  return 0;
     }
}

int main()
{
	int a, b, i;
	int c[50] = {0};
	queue *q = NULL;

	scanf("%d %d", &a, &b);

	a -= b;

	if (a < 0) a = -a;

	q = push(q, make_pair(a + 10, 0));

	while (1) {
		pair p = front(q);

		q = pop(q);

		if (p.first == 10) {
			printf("%d\n", p.second);

			return 0;
		}

		if (c[p.first] == 1) continue;

		c[p.first] = 1;

		if (p.first + 1 < 50 && c[p.first + 1] == 0) q = push(q, make_pair(p.first + 1, p.second + 1));
		if (p.first + 5 < 50 && c[p.first + 5] == 0) q = push(q, make_pair(p.first + 5, p.second + 1));
		if (p.first - 1 >= 0 && c[p.first - 1] == 0) q = push(q, make_pair(p.first - 1, p.second + 1));
		if (p.first - 5 >= 0 && c[p.first - 5] == 0) q = push(q, make_pair(p.first - 5, p.second + 1));
		if (p.first - 10 >= 0 && c[p.first - 10] == 0) q = push(q, make_pair(p.first - 10, p.second + 1));
	}

	return 0;
}

Submission Info

Submission Time
Task B - リモコン
User kawatea
Language C (GCC 4.4.7)
Score 100
Code Size 2241 Byte
Status AC
Exec Time 19 ms
Memory 712 KB

Compile Error

./Main.c: In function ‘main’:
./Main.c:110: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result

Judge Result

Set Name all
Score / Max Score 100 / 100
Status
AC × 35
Set Name Test Cases
all 00_maxdiff.txt, 00_maxret.txt, 00_sample1.txt, 00_sample2.txt, 00_sample3.txt, 01_rnd_00.txt, 01_rnd_01.txt, 01_rnd_02.txt, 01_rnd_03.txt, 01_rnd_04.txt, 01_rnd_05.txt, 01_rnd_06.txt, 01_rnd_07.txt, 01_rnd_08.txt, 01_rnd_09.txt, 01_rnd_10.txt, 01_rnd_11.txt, 01_rnd_12.txt, 01_rnd_13.txt, 01_rnd_14.txt, 01_rnd_15.txt, 01_rnd_16.txt, 01_rnd_17.txt, 01_rnd_18.txt, 01_rnd_19.txt, 01_rnd_20.txt, 01_rnd_21.txt, 01_rnd_22.txt, 01_rnd_23.txt, 01_rnd_24.txt, 01_rnd_25.txt, 01_rnd_26.txt, 01_rnd_27.txt, 01_rnd_28.txt, 01_rnd_29.txt
Case Name Status Exec Time Memory
00_maxdiff.txt AC 18 ms 584 KB
00_maxret.txt AC 18 ms 592 KB
00_sample1.txt AC 19 ms 128 KB
00_sample2.txt AC 18 ms 128 KB
00_sample3.txt AC 18 ms 128 KB
01_rnd_00.txt AC 18 ms 596 KB
01_rnd_01.txt AC 18 ms 128 KB
01_rnd_02.txt AC 18 ms 592 KB
01_rnd_03.txt AC 18 ms 592 KB
01_rnd_04.txt AC 18 ms 128 KB
01_rnd_05.txt AC 18 ms 128 KB
01_rnd_06.txt AC 19 ms 712 KB
01_rnd_07.txt AC 18 ms 128 KB
01_rnd_08.txt AC 18 ms 128 KB
01_rnd_09.txt AC 18 ms 128 KB
01_rnd_10.txt AC 19 ms 128 KB
01_rnd_11.txt AC 17 ms 128 KB
01_rnd_12.txt AC 18 ms 128 KB
01_rnd_13.txt AC 17 ms 128 KB
01_rnd_14.txt AC 17 ms 128 KB
01_rnd_15.txt AC 16 ms 128 KB
01_rnd_16.txt AC 17 ms 128 KB
01_rnd_17.txt AC 18 ms 128 KB
01_rnd_18.txt AC 18 ms 0 KB
01_rnd_19.txt AC 18 ms 588 KB
01_rnd_20.txt AC 16 ms 128 KB
01_rnd_21.txt AC 18 ms 128 KB
01_rnd_22.txt AC 18 ms 128 KB
01_rnd_23.txt AC 16 ms 128 KB
01_rnd_24.txt AC 17 ms 128 KB
01_rnd_25.txt AC 17 ms 128 KB
01_rnd_26.txt AC 18 ms 584 KB
01_rnd_27.txt AC 18 ms 128 KB
01_rnd_28.txt AC 18 ms 128 KB
01_rnd_29.txt AC 17 ms 128 KB