File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ from collections import deque
2+ n , k = map (int , input ().split ())
3+
4+ # N x N 크기의 보드 전체를 0으로 초기화
5+ board = []
6+ data = []
7+
8+ for i in range (n ):
9+ # 보드 정보를 한 줄 단위로 입력
10+ board .append (list (map (int , input ().split ())))
11+ for j in range (n ):
12+ # 해당 위치에 바이러스가 존재하는 경우
13+ if board [i ][j ] != 0 :
14+ # (바이러스 종류, 시간, 위치 X, 위치 Y) 삽입
15+ data .append ((board [i ][j ], 0 , i , j ))
16+
17+ # 정렬 이후에 큐로 옮기기
18+ data .sort ()
19+ q = deque (data )
20+
21+ target_s , target_x , target_y = map (int , input ().split ())
22+
23+ # 바이러스가 퍼져나갈 수 있는 4가지의 위치
24+ dx = [- 1 , 0 , 1 , 0 ]
25+ dy = [0 , 1 , 0 , - 1 ]
26+
27+ while q :
28+ virus , s , x , y = q .popleft ()
29+ # 정확히 s초가 지나거나, 큐가 빌 때까지 반복
30+ if s == target_s :
31+ break
32+ # 4가지 위치를 각각 확인
33+ for i in range (4 ):
34+ nx = x + dx [i ]
35+ ny = y + dy [i ]
36+ # 해당 위치로 이동할 수 있는 경우
37+ if 0 <= nx and nx < n and 0 <= ny and ny < n :
38+ # 방문한 적 없다면, 그 위치에 바이러스 넣기
39+ if board [nx ][ny ] == 0 :
40+ board [nx ][ny ] = virus
41+ q .append ((virus , s + 1 , nx , ny ))
42+
43+ print (board [target_x - 1 ][target_y - 1 ])
You can’t perform that action at this time.
0 commit comments