DHistory
[Baekjoon] DFS/BFS - 16173 점프왕 쩰리 (Small) 본문
문제
풀이
import sys
n = int(sys.stdin.readline().rstrip())
maps = []
for _ in range(n):
lines = list(map(int ,sys.stdin.readline().rstrip().split()))
maps.append(lines)
dx = [1, 0]
dy = [0, 1]
visited = [[False for _ in range(n)] for _ in range(n)]
def solution(maps, visited):
queue = [(0, 0, maps[0][0])]
visited[0][0] = True
while queue:
x, y, distance = queue.pop()
for i in range(len(dx)):
nx = x + dx[i] * distance
ny = y + dy[i] * distance
if not (0 <= nx < n and 0 <= ny < n):
continue
if visited[nx][ny]:
continue
queue.append((nx, ny, maps[nx][ny]))
visited[nx][ny] = True
if maps[nx][ny] == -1:
return "Haru" * 2
return "Hing"
print(solution(maps, visited))
채점 결과
'Computer Science > Algorithm' 카테고리의 다른 글
[Baekjoon] DFS/BFS - 1260 DFS와 BFS (0) | 2023.09.04 |
---|---|
[Baekjoon] DFS/BFS - 2606 바이러스 (0) | 2023.09.04 |
[Baekjoon] Greedy - 17503 맥주 축제 (0) | 2023.08.30 |
[Baekjoon] Greedy - 16206 롤케이크 (0) | 2023.08.30 |
[Baekjoon] Greedy - 1911 흙길 보수하기 (0) | 2023.08.30 |