Skip to content

Commit 7e9a583

Browse files
committed
[BOJ] 경쟁적 전염 / 골드5 / 55분
https://www.acmicpc.net/problem/18405
1 parent d3a46c7 commit 7e9a583

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from collections import deque
2+
import sys
3+
input = sys.stdin.readline
4+
5+
dr = [1, -1, 0, 0] # down, up, right, left
6+
dc = [0, 0, 1, -1]
7+
8+
N, K = map(int, input().split())
9+
board = [] # 바이러스 정보 받아올 배열
10+
for _ in range(N):
11+
board.append(list(map(int, input().split())))
12+
13+
S, X, Y = map(int, input().split()) # 시간, 행, 열
14+
15+
q = []
16+
for i in range(N):
17+
for j in range(N):
18+
if board[i][j] != 0: # 바이러스가 있는 위치
19+
q.append((board[i][j], i, j, 0)) # 바이러스 정보, 행, 열, 흘러간 시간
20+
q.sort() # (주의) 리스트로 받아 정렬 후 queue로 변경!
21+
q = deque(q)
22+
23+
while q: # BFS
24+
viru, row, col, time = q.popleft()
25+
if time == S: # 시간이 S만큼 지났다면 종료
26+
break
27+
for d in range(4): # 상하좌우 이동
28+
r = row + dr[d]
29+
c = col + dc[d]
30+
if -1 < r < N and -1 < c < N and not board[r][c]: # 범위를 벗어나지 않고 위치 값이 0일 때
31+
board[r][c] = viru # 바이러스 배치
32+
q.append((viru, r, c, time+1)) # 다음 번 위치를 큐에 저장
33+
34+
print(board[X-1][Y-1])

0 commit comments

Comments
 (0)