https://www.acmicpc.net/problem/7569
ํ์ด ๊ณผ์
์ ๋ฒ์ ํผ ํ ๋งํ ๋ฌธ์ ์ ๊ฑฐ์ ์ ์ฌํ๋ค. ์ฐจ์ด์ ์ z์ถ์ด ์๊น.
๋ฌธ์ ์์ M,N,H ์ต๋๊ฐ์ด ๋ชจ๋ 100์ผ๋ก ํฐ์๊ฐ ์๋์ฌ์ ๊ทธ๋ฅ 3์ฐจ์ ๋ฐฐ์ด์ ์ฌ์ฉํ๊ธฐ๋ก ํ๋ค.
๋ฐ๋ผ์ z์ถ ๊ด๋ จ๋ ๋ถ๋ถ๋ง ์ด์ ๋ฌธ์ ์ ์ถ๊ฐํ๋ฉด ๋๋ค. ์ด์ ๋ฌธ์ ํ์ด์ ๋ํ ์ ๋ณด๋ 7576-ํ ๋งํ ์ฐธ์กฐ
import sys
from collections import deque
input = sys.stdin.readline
dz = [1, -1, 0, 0, 0, 0] # ์, ์๋, ์ผ์ชฝ, ์ค๋ฅธ์ชฝ, ์, ๋ค
dy = [0, 0, 0, 0, -1, 1]
dx = [0, 0, -1, 1, 0, 0]
M, N, H = map(int,input().rstrip().split())
tomato_box = [[[] for _ in range(N)] for _ in range(H)] #z, y, x ์ขํ
day = [[[0 for _ in range(M)] for _ in range(N)] for _ in range(H)]
tomato = deque()
for i in range(H):
for j in range(N):
tomato_box[i][j].extend([int(x) for x in input().rstrip().split()])
for k in range(M):
if tomato_box[i][j][k] == 1:
tomato.append([i,j,k])
def bfs():
while tomato:
t = tomato.popleft()
z, y, x = t[0], t[1], t[2]
for i in range(6):
nz, ny, nx = z + dz[i], y + dy[i], x + dx[i]
if 0 <= nz < H and 0 <= ny < N and 0 <= nx < M:
if tomato_box[nz][ny][nx] == 0:
tomato_box[nz][ny][nx] = 1
day[nz][ny][nx] = day[z][y][x] + 1
tomato.append([nz,ny,nx])
bfs()
zeroflag = False
resultday = 0
for i in range(H):
for j in range(N):
for k in range(M):
if tomato_box[i][j][k] == 0:
zeroflag = True
if resultday < day[i][j][k]:
resultday = day[i][j][k]
if zeroflag:
print(-1)
else:
print(resultday)
'๐งฉ Problem Solving > [๋ฐฑ์ค]' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] 10026 ์ ๋ก์์ฝ(python ํ์ด์ฌ) (0) | 2022.06.15 |
---|---|
[๋ฐฑ์ค] 1655 ๊ฐ์ด๋ฐ๋ฅผ๋งํด์ (python ํ์ด์ฌ) (0) | 2022.06.14 |
[๋ฐฑ์ค] 13549 ์จ๋ฐ๊ผญ์ง3 (python ํ์ด์ฌ) (0) | 2022.06.13 |
[๋ฐฑ์ค] 2252 ์ค์ธ์ฐ๊ธฐ (python ํ์ด์ฌ) (0) | 2022.06.11 |
[๋ฐฑ์ค] 11718 ๊ทธ๋๋ก ์ถ๋ ฅํ๊ธฐ (python ํ์ด์ฌ) (0) | 2022.06.10 |