문제 확인하기
2. 정답 코드 (Python, memory: 34160KB, time: 72ms)
from collections import deque
def is_valid(y, x, N):
return 0 <= y < N and 0 <= x < N
def can_reach_end(N, li):
directions = [(1, 0), (0, 1)]
queue = deque([(0, 0, li[0][0])])
while queue:
y, x, d = queue.popleft()
for dy, dx in directions:
Y, X = y + d * dy, x + d * dx
if is_valid(Y, X, N) and d != 0:
if Y == X == N - 1:
return True
queue.append((Y, X, li[Y][X]))
return False
def main():
N = int(input())
lst = [list(map(int, input().split())) for _ in range(N)]
result = can_reach_end(N, lst)
print("HaruHaru" if result else "Hing")
if __name__ == "__main__":
main()