Submission #28170

# Submission time Handle Problem Language Result Execution time Memory
28170 2017-07-15T14:03:02 Z 시.공.조.아.(#1207, archane5276) The City and The Bitcoin (FXCUP2_city) C
0 / 1
76 ms 1116 KB
#include <stdio.h>
#include <stdlib.h>

short Box[10][10];

int di[2] = { 0,1};
int dj[2] = { 1,0};

int N, M, result;

typedef struct {
	short row, col;
	struct ListNode *next;
}ListNode;

typedef struct {
	ListNode *front, *rear;
	short cnt;
}Queue;

void init(Queue *Q)
{
	Q->front = Q->rear = NULL;
	Q->cnt = 0;
}

int Queue_Emtpy(Queue *Q)
{
	if (Q->cnt == 0)
		return 1;
	else
		return 0;
}

void Enqueue(Queue *Q, int row, int col)
{
	ListNode *temp = (ListNode *)malloc(sizeof(ListNode));
	temp->row = row;
	temp->col = col;
	temp->next = NULL;
	if (Queue_Emtpy(Q)) {
		Q->front = temp;
	}
	else {
		Q->rear->next = temp;
	}
	Q->rear = temp;
	Q->cnt++;
}

ListNode *Dequeue(Queue *Q)
{
	ListNode *current;
	current = Q->front;
	Q->front = current->next;
	Q->cnt--;
	return current;
}

void go(Queue *Q, int i, int j)
{
	int k;
	for (k = 0; k < 2; k++) {
		if (i == M - 1 && j == N - 1) {
			result = 1;
			break;
		}
		int ni = i + di[k];
		int nj = j + dj[k];

		if (0 <= nj && nj < N && 0 <= ni && ni < M)
		{
			if (Box[ni][nj] == 1){
				if (ni == M - 1 && nj == N - 1) {
					result = 1;
					break;
				}
				else
					Enqueue(Q, ni, nj);
			}
		}
	}
}

int main()
{
	int i, j;
	Queue Q;
	ListNode *temp;
	init(&Q);
	scanf("%d %d", &N, &M);
	for (i = 0; i < M; i++) {
		for (j = 0; j < N; j++) {
			scanf("%d", &Box[i][j]);
		}
	}
	Box[0][0] = 1;
	Box[M - 1][N - 1] = 1;
	Enqueue(&Q, 0, 0);
	while (!Queue_Emtpy(&Q)) {
		temp = Dequeue(&Q);
		go(&Q, temp->row, temp->col);
	}
	if (result == 1)
		printf("Yes");
	else
		printf("No");
}

Compilation message

city.c: In function 'Enqueue':
city.c:45:17: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
   Q->rear->next = temp;
                 ^
city.c: In function 'Dequeue':
city.c:55:11: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
  Q->front = current->next;
           ^
city.c: In function 'main':
city.c:94:10: warning: format '%d' expects argument of type 'int *', but argument 2 has type 'short int *' [-Wformat=]
    scanf("%d", &Box[i][j]);
          ^
city.c:91:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &M);
  ^
city.c:94:4: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &Box[i][j]);
    ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1116 KB Output is correct
2 Correct 0 ms 1116 KB Output is correct
3 Correct 0 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Runtime error 76 ms 1116 KB Execution timed out (wall clock limit exceeded)
6 Halted 0 ms 0 KB -