BOJ - 6593 - 상범 빌딩
Updated:
import sys
from collections import deque
dx = [-1, 1, 0, 0, 0, 0]
dy = [0, 0, -1, 1, 0, 0]
dz = [0, 0, 0, 0, -1, 1]
sx, sy, sz = 0, 0, 0
ex, ey, ez = 0, 0, 0
def BFS(arr, visit, L, R, C):
global sx, sy, sz, ex, ey, ez
dq = deque()
dq.append((sx, sy, sz))
while dq:
x, y, z = dq.popleft()
if x == ex and y == ey and z == ez:
print("Escaped in %d minute(s)."% visit[x][y][z])
return
for i in range(6):
nx, ny, nz = x + dx[i], y + dy[i], z + dz[i]
if 0 <= nx < L and 0 <= ny < R and 0 <= nz < C:
if arr[nx][ny][nz] != '#' and not visit[nx][ny][nz]:
visit[nx][ny][nz] = visit[x][y][z] + 1
dq.append((nx, ny, nz))
print("Trapped!")
return
def solution():
global sx, sy, sz, ex, ey, ez
while True:
L, R, C = map(int, sys.stdin.readline().split())
if L == 0:
break
arr = [[[] * C for _ in range(R)] for _ in range(L)]
check = [[[0] * C for _ in range(R)] for _ in range(L)]
for i in range(L):
arr[i] = [list(map(str, sys.stdin.readline().strip())) for _ in range(R)]
input()
for i in range(L):
for j in range(R):
for k in range(C):
if arr[i][j][k] == 'S':
sx, sy, sz = i, j, k
elif arr[i][j][k] == 'E':
ex, ey, ez = i, j, k
BFS(arr, check, L, R, C)
solution()
https://www.acmicpc.net/problem/6593
Leave a comment