코테 백준 6593 골드5

김동윤·2023년 8월 14일
0
post-thumbnail

백준 6593
기존의 bfs문제와 같다. 하지만 기존과 차이점이있다면 탐색을 할 때 위,아래도 탐색을 해야한단것이다. 그래서 dz배열을 생성해주어서 똑같이 탐색을 하면된다. 또한 기존의 데이터가 담긴 graph를 3차원 배열로 만들어주면된다.

import sys
from collections import deque
input=sys.stdin.readline

dx=[-1,1,0,0,0,0]
dy=[0,0,1,-1,0,0]
dz=[0,0,0,0,1,-1]

def bfs(i,j,k):
    que=deque()
    que.append((i,j,k))
    graph[i][j][k]=0
    while que:
        z,y,x=que.popleft()
        for i in range(6):
            new_z=z+dz[i]
            new_y=y+dy[i]
            new_x=x+dx[i]
            if (0<=new_z<l) and (0<=new_y<r) and (0<=new_x<c):
                if graph[new_z][new_y][new_x]=='.':
                    graph[new_z][new_y][new_x]=graph[z][y][x]+1
                    que.append((new_z,new_y,new_x))
                elif graph[new_z][new_y][new_x]=='E':
                    graph[new_z][new_y][new_x]=graph[z][y][x]+1
                    print("Escaped in {0} minute(s).".format(graph[new_z][new_y][new_x]))
                    return
    print('Trapped!')

while True:
    l,r,c=map(int,input().split())
    if l==0 and r==0 and c==0:
        break
    else:
        graph=[]
        for _ in range(l):
            graph.append([list(map(str,input().rstrip())) for _ in range(r)])
            input()
        for i in range(l):
            for j in range(r):
                for k in range(c):
                    if graph[i][j][k]=='S':
                        bfs(i,j,k)
profile
Back-End

0개의 댓글