Follows 532.c (Total 106 lines):

/* @JUDGE_ID:4461XX 532 */
/* A */
#include<stdio.h>
#define MAX 40
int map[MAX][MAX][MAX] , ans[MAX][MAX][MAX] ;
struct queue{
	int x ;
	int y ;
	int z ;
}queue[100000] ;
void run( void )
{
	int head , tail , yes ;
	for( yes=tail=head=0 ; tail-head>=0 ; head++ ){
		if( map[queue[head].x][queue[head].y][queue[head].z] == 3 ){
			printf( "Escaped in %d minute(s).\n" , ans[queue[head].x][queue[head].y][queue[head].z] ) ;
			yes = 1 ;
			break ;
		}
		if( map[queue[head].x+1][queue[head].y][queue[head].z] ){
			if( !ans[queue[head].x+1][queue[head].y][queue[head].z] ){
				ans[queue[head].x+1][queue[head].y][queue[head].z] = ans[queue[head].x][queue[head].y][queue[head].z] + 1 ;
				tail++ ;
				queue[tail].x = queue[head].x + 1 ;
				queue[tail].y = queue[head].y ;
				queue[tail].z = queue[head].z ;
			}
		}
		if( map[queue[head].x-1][queue[head].y][queue[head].z] ){
			if( !ans[queue[head].x-1][queue[head].y][queue[head].z] ){
				ans[queue[head].x-1][queue[head].y][queue[head].z] = ans[queue[head].x][queue[head].y][queue[head].z] + 1 ;
				tail++ ;
				queue[tail].x = queue[head].x - 1 ;
				queue[tail].y = queue[head].y ;
				queue[tail].z = queue[head].z ;
			}
		}
		if( map[queue[head].x][queue[head].y+1][queue[head].z] ){
			if( !ans[queue[head].x][queue[head].y+1][queue[head].z] ){
				ans[queue[head].x][queue[head].y+1][queue[head].z] = ans[queue[head].x][queue[head].y][queue[head].z] + 1 ;
				tail++ ;
				queue[tail].x = queue[head].x ;
				queue[tail].y = queue[head].y + 1 ;
				queue[tail].z = queue[head].z ;
			}
		}
		if( map[queue[head].x][queue[head].y-1][queue[head].z] ){
			if( !ans[queue[head].x][queue[head].y-1][queue[head].z] ){
				ans[queue[head].x][queue[head].y-1][queue[head].z] = ans[queue[head].x][queue[head].y][queue[head].z] + 1 ;
				tail++ ;
				queue[tail].x = queue[head].x ;
				queue[tail].y = queue[head].y - 1 ;
				queue[tail].z = queue[head].z ;
			}
		}
		if( map[queue[head].x][queue[head].y][queue[head].z+1] ){
			if( !ans[queue[head].x][queue[head].y][queue[head].z+1] ){
				ans[queue[head].x][queue[head].y][queue[head].z+1] = ans[queue[head].x][queue[head].y][queue[head].z] + 1 ;
				tail++ ;
				queue[tail].x = queue[head].x ;
				queue[tail].y = queue[head].y ;
				queue[tail].z = queue[head].z + 1 ;
			}
		}
		if( map[queue[head].x][queue[head].y][queue[head].z-1] ){
			if( !ans[queue[head].x][queue[head].y][queue[head].z-1] ){
				ans[queue[head].x][queue[head].y][queue[head].z-1] = ans[queue[head].x][queue[head].y][queue[head].z] + 1 ;
				tail++ ;
				queue[tail].x = queue[head].x ;
				queue[tail].y = queue[head].y ;
				queue[tail].z = queue[head].z - 1 ;
			}
		}
	}
	if( !yes ) printf( "Trapped!\n" ) ;
}
void main( void )
{
	int c , l , r , i , j , k ;
	char ch ;
/*	freopen( "C:\\windows\\desktop\\532.txt" , "r" , stdin ) ;*/
	while( scanf( "%d %d %d\n" , &c , &l , &r ) == 3 ){
		if( !c && !l && !r ) break ;
		/* can pass --> 1 ; can't --> 0 ; start --> 2 ; end --> 3 */
		for( i=1 ; i<=c ; i++ , scanf( "\n" ) )
			for( j=1 ; j<=l ; j++ , scanf( "\n" ) )
				for( k=1 ; k<=r ; k++ ){
					scanf( "%c" , &ch ) ;
					switch ( ch ){
						case 'S' : map[i][j][k] = 2 ;
								   queue[0].x = i ;
								   queue[0].y = j ;
								   queue[0].z = k ;
								   break ;
						case 'E' : map[i][j][k] = 3 ; break ;
						case '#' : map[i][j][k] = 0 ; break ;
						case '.' : map[i][j][k] = 1 ; break ;
					}
					map[0][j][k] = map[c+1][j][k] = 0 ;
					map[i][0][k] = map[i][j+1][k] = 0 ;
					map[i][j][0] = map[i][j][k+1] = 0 ;
				    ans[i][j][k] = 0 ;
				}
		run() ;
	}
}

Back to statistics
Ya-Lin Huang (C)
huangyl@gmail.com