Skip to content

Commit d909691

Browse files
authored
Update 3.py
1 parent 4eb4ef5 commit d909691

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

13/3.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
n, k = map(int, input().split())
44

5-
board = [] # 전체 보드 정보를 담는 리스트
5+
graph = [] # 전체 보드 정보를 담는 리스트
66
data = [] # 바이러스에 대한 정보를 담는 리스트
77

88
for i in range(n):
99
# 보드 정보를 한 줄 단위로 입력
10-
board.append(list(map(int, input().split())))
10+
graph.append(list(map(int, input().split())))
1111
for j in range(n):
1212
# 해당 위치에 바이러스가 존재하는 경우
13-
if board[i][j] != 0:
13+
if graph[i][j] != 0:
1414
# (바이러스 종류, 시간, 위치 X, 위치 Y) 삽입
15-
data.append((board[i][j], 0, i, j))
15+
data.append((graph[i][j], 0, i, j))
1616

17-
# 정렬 이후에 큐로 옮기기
17+
# 정렬 이후에 큐로 옮기기 (낮은 번호의 바이러스가 먼저 증식하므로)
1818
data.sort()
1919
q = deque(data)
2020

@@ -23,21 +23,22 @@
2323
# 바이러스가 퍼져나갈 수 있는 4가지의 위치
2424
dx = [-1, 0, 1, 0]
2525
dy = [0, 1, 0, -1]
26-
26+
27+
# 너비 우선 탐색(BFS) 진행
2728
while q:
2829
virus, s, x, y = q.popleft()
2930
# 정확히 s초가 지나거나, 큐가 빌 때까지 반복
3031
if s == target_s:
3132
break
32-
# 4가지 위치를 각각 확인
33+
# 현재 노드에서 주변 4가지 위치를 각각 확인
3334
for i in range(4):
3435
nx = x + dx[i]
3536
ny = y + dy[i]
3637
# 해당 위치로 이동할 수 있는 경우
3738
if 0 <= nx and nx < n and 0 <= ny and ny < n:
3839
# 아직 방문하지 않은 위치라면, 그 위치에 바이러스 넣기
39-
if board[nx][ny] == 0:
40-
board[nx][ny] = virus
40+
if graph[nx][ny] == 0:
41+
graph[nx][ny] = virus
4142
q.append((virus, s + 1, nx, ny))
4243

43-
print(board[target_x - 1][target_y - 1])
44+
print(graph[target_x - 1][target_y - 1])

0 commit comments

Comments
 (0)