Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

경쟁적 전염 질문 #192

Open
seungchan2022 opened this issue Oct 12, 2022 · 0 comments
Open

경쟁적 전염 질문 #192

seungchan2022 opened this issue Oct 12, 2022 · 0 comments

Comments

@seungchan2022
Copy link

seungchan2022 commented Oct 12, 2022

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

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)라고 뜨던데 그 이유를 모르겠습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant