You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for i in range(n):
graph.append(list(map(int, input().split())))
for j in range(n):
# 해당 위치에 바이러스가 존재하는 경우
if graph[i][j] != 0:
# (바이러스 종류, 시간, X좌표, Y좌표) 삽입
data.append((graph[i][j], 0, i, j))
while q:
virus, s, x, y = q.popleft()
# s초가 지나거나, 큐가 빌때 까지 반복
if s == target_s:
break
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
# 이동할수 있는 경우
if 0 <= nx < n and 0 <= ny < n:
# 아직 방문하지 않았다면
if graph[nx][ny] == 0:
# 바이러스 전파
graph[nx][ny] = virus
q.append((virus, s + 1, nx, ny))
print(graph[target_x - 1][target_y - 1])
위 코드에서 q에서 data를 삽입 할때
q = deque(data) 말고
q = deque()
q.append(data)
이런식으로 하면 백준에서 런타임 에러(ValueError)라고 뜨던데 그 이유를 모르겠습니다.
The text was updated successfully, but these errors were encountered:
from collections import deque
n, k = map(int, input().split())
graph = [] # 전체 맵 리스트
data = [] # 바이러스 정보
for i in range(n):
graph.append(list(map(int, input().split())))
for j in range(n):
# 해당 위치에 바이러스가 존재하는 경우
if graph[i][j] != 0:
# (바이러스 종류, 시간, X좌표, Y좌표) 삽입
data.append((graph[i][j], 0, i, j))
data.sort()
q = deque(data)
target_s, target_x, target_y = map(int, input().split())
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]
while q:
virus, s, x, y = q.popleft()
# s초가 지나거나, 큐가 빌때 까지 반복
if s == target_s:
break
print(graph[target_x - 1][target_y - 1])
위 코드에서 q에서 data를 삽입 할때
q = deque(data) 말고
q = deque()
q.append(data)
이런식으로 하면 백준에서 런타임 에러(ValueError)라고 뜨던데 그 이유를 모르겠습니다.
The text was updated successfully, but these errors were encountered: