Submission #1437612


Source Code Expand

#include <stdio.h>
#include <memory.h>
typedef struct{
	int x,y;
}queue;
	
	int main(void){
		int r,c,sy,sx,gy,gx,i,head,tail,dy[]={1,-1,0,0},dx[]={0,0,1,-1},f[50][50];
		char m[50][50];
		queue q[100000];
		memset(f,-1,sizeof(f));//f[50][50]に-1をセットしている
		memset(q,0,10000); //q[100000]に0をセットしている
		scanf("%d %d",&r,&c);
		scanf("%d %d",&sy,&sx);
		scanf("%d %d",&gy,&gx);
		for(i=0;i<r;i++){
			scanf("%s",&m[i]);
		}
		r--;c--;sy--;sx--;gy--;gx--;//配列の添え字と対応させるために数値を1引く
		head=tail=0;//headとtailは0
		q[head].y=sy;//q[head]のyはsyの座標が入る
		q[head].x=sx;//q[head]のxはsxの座標が入る
		f[sy][sx]=0;//距離は0
		while(q[head].x!=0){//q[head].xが!=0の間繰り返す
			int ty=q[head].y;
			int tx=q[head].x;
			head++;
			for(i=0;i<4;i++){
				int ny=ty+dy[i];
				int nx=tx+dx[i];
				if(m[ny][nx]=='.'&&f[ny][nx]==-1){
					f[ny][nx]=f[ty][tx]+1;
					tail++;
					q[tail].y=ny;
					q[tail].x=nx;
				}
			}
		}
		printf("%d\n",f[gy][gx]);
		return 0;
	}

Submission Info

Submission Time
Task C - 幅優先探索
User s6challe
Language C (GCC 5.4.1)
Score 100
Code Size 1101 Byte
Status AC
Exec Time 1 ms
Memory 256 KB

Compile Error

./Main.c: In function ‘main’:
./Main.c:17:10: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[50]’ [-Wformat=]
    scanf("%s",&m[i]);
          ^
./Main.c:13:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&r,&c);
   ^
./Main.c:14:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&sy,&sx);
   ^
./Main.c:15:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&gy,&gx);
   ^
./Main.c:17:4: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
    scanf("%s",&m[i]);
    ^

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 0 ms 128 KB
subtask0_sample02.txt AC 0 ms 128 KB
subtask0_sample03.txt AC 1 ms 256 KB
subtask1_01.txt AC 1 ms 128 KB
subtask1_02.txt AC 1 ms 128 KB
subtask1_03.txt AC 0 ms 128 KB
subtask1_04.txt AC 1 ms 256 KB
subtask1_05.txt AC 1 ms 256 KB
subtask1_06.txt AC 1 ms 256 KB
subtask1_07.txt AC 0 ms 128 KB
subtask1_08.txt AC 0 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 256 KB
subtask1_12.txt AC 1 ms 256 KB
subtask1_13.txt AC 1 ms 128 KB
subtask1_14.txt AC 0 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 1 ms 128 KB
subtask1_20.txt AC 1 ms 128 KB
subtask1_21.txt AC 1 ms 128 KB
subtask1_22.txt AC 1 ms 128 KB