Submission #1318677


Source Code Expand

#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX_ELEMENT 50
#define MAX_LOOP 2304
#define WALL  -2
#define SPACE -1

int aaIntMaze[MAX_ELEMENT+1][MAX_ELEMENT+1];
int check_neighbor(int,int,int);


int main() {

	char aaMaze[MAX_ELEMENT+1][MAX_ELEMENT+1];
	char sInput[MAX_ELEMENT+1]="";
	char* psInput;

	int nRow=0;
	int nCol=0;
	int anStart[2]={0,0};
	int anGoal[2]={0,0};

	int i=0;
	int j=0;
	int loop=0;
	int nTargetNumber=0;
	int isFoundAnswer=0;

	for (i=0;i<MAX_ELEMENT;i++){
		for (j=0;j<MAX_ELEMENT;j++){
			aaMaze[i][j]='\0';
			aaIntMaze[i][j]=WALL;
		}
	}

	// read line 1
	gets(sInput);
	psInput=strtok(sInput," ");
	nRow=atoi(psInput);
	psInput=strtok(NULL," ");
	nCol=atoi(psInput);
	// read line 2
	gets(sInput);
	psInput=strtok(sInput," ");
	anStart[0]=atoi(psInput);
	psInput=strtok(NULL," ");
	anStart[1]=atoi(psInput);
	// read line 3
	gets(sInput);
	psInput=strtok(sInput," ");
	anGoal[0]=atoi(psInput);
	psInput=strtok(NULL," ");
	anGoal[1]=atoi(psInput);
	// read line 4...
	for (i=0;i<nRow;i++){
		gets(sInput);
		strcpy(aaMaze[i],sInput);
	}
	//convert maze char->int
	for (i=0;i<MAX_ELEMENT;i++){
		for (j=0;j<MAX_ELEMENT;j++){
			if (aaMaze[i][j]=='.'){
					aaIntMaze[i][j]=SPACE;
			}
		}
	}
	//put start position
	aaIntMaze[anStart[0]-1][anStart[1]-1]=0;

	while( isFoundAnswer==0 && nTargetNumber<MAX_LOOP){
		for (i=0;i<MAX_ELEMENT;i++){
			for (j=0;j<MAX_ELEMENT;j++){
				if (aaIntMaze[i][j]==nTargetNumber) {
					check_neighbor(i,j,nTargetNumber);
				}
			}
		}
		nTargetNumber++;
		if (aaIntMaze[anGoal[0]-1][anGoal[1]-1]==nTargetNumber){
			isFoundAnswer=1;
		}
	}

	printf("%d\n",nTargetNumber);
	return 0;

}

int check_neighbor(int y,int x,int target){
	int next = target+1;
	//north
	if (aaIntMaze[y-1][x] == SPACE){
		aaIntMaze[y-1][x] = next;
	}
	// south
	if (aaIntMaze[y+1][x] == SPACE){
		aaIntMaze[y+1][x] = next;
	}
	// east
	if (aaIntMaze[y][x+1] == SPACE){
		aaIntMaze[y][x+1] = next;
	}
	// west
	if (aaIntMaze[y][x-1] == SPACE){
		aaIntMaze[y][x-1] = next;
	}
	return 0;
}

Submission Info

Submission Time
Task C - 幅優先探索
User unirita137
Language C (GCC 5.4.1)
Score 100
Code Size 2211 Byte
Status AC
Exec Time 4 ms
Memory 128 KB

Compile Error

./Main.c: In function ‘main’:
./Main.c:40:2: warning: implicit declaration of function ‘gets’ [-Wimplicit-function-declaration]
  gets(sInput);
  ^
/tmp/cchI3MOx.o: In function `main':
Main.c:(.text.startup+0x94): warning: the `gets' function is dangerous and should not be used.

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 3
AC × 25
Set Name Test Cases
Sample subtask0_sample01.txt, subtask0_sample02.txt, subtask0_sample03.txt
All subtask0_sample01.txt, subtask0_sample02.txt, subtask0_sample03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask1_21.txt, subtask1_22.txt
Case Name Status Exec Time Memory
subtask0_sample01.txt AC 1 ms 128 KB
subtask0_sample02.txt AC 1 ms 128 KB
subtask0_sample03.txt AC 1 ms 128 KB
subtask1_01.txt AC 4 ms 128 KB
subtask1_02.txt AC 4 ms 128 KB
subtask1_03.txt AC 1 ms 128 KB
subtask1_04.txt AC 1 ms 128 KB
subtask1_05.txt AC 1 ms 128 KB
subtask1_06.txt AC 1 ms 128 KB
subtask1_07.txt AC 1 ms 128 KB
subtask1_08.txt AC 1 ms 128 KB
subtask1_09.txt AC 1 ms 128 KB
subtask1_10.txt AC 1 ms 128 KB
subtask1_11.txt AC 1 ms 128 KB
subtask1_12.txt AC 1 ms 128 KB
subtask1_13.txt AC 1 ms 128 KB
subtask1_14.txt AC 1 ms 128 KB
subtask1_15.txt AC 1 ms 128 KB
subtask1_16.txt AC 1 ms 128 KB
subtask1_17.txt AC 1 ms 128 KB
subtask1_18.txt AC 1 ms 128 KB
subtask1_19.txt AC 2 ms 128 KB
subtask1_20.txt AC 2 ms 128 KB
subtask1_21.txt AC 3 ms 128 KB
subtask1_22.txt AC 3 ms 128 KB