[백준] 15558번 점프 게임 - 파이썬/BFS

JinUk Lee·2022년 12월 26일
0

백준 알고리즘

목록 보기
1/78

https://www.acmicpc.net/problem/15558


from collections import deque

N,k = map(int,input().split())

graph_left = list(map(int,input()))
graph_right = list(map(int,input()))
visited_left = [ 0 for _ in range(N) ]
visited_rigth = [ 0 for _ in range(N) ]
graph = [ graph_left, graph_right]
visted = [visited_left, visited_rigth]
visted[0][0]=True

def bfs():
    i = 0
    q = deque([(i, 0,0)])

    while q:

        i,pos,t = q.popleft() # 인덱스, 위치, 시간
        dx = [1,-1,k]

        for j in range(3):

            nx = i + dx[j]

            if nx >= N:
                return print(1)

            if t< nx and graph[pos][nx] == 1 and j != 2:
                if not visted[pos][nx]:
                    visted[pos][nx] = True
                    q.append((nx,pos,t+1))

            elif t< nx and graph[1-pos][nx] == 1 and j == 2:
                if not visted[1-pos][nx]:
                    visted[1 - pos][nx] = True
                    q.append((nx,1-pos,t+1))

    print(0)


bfs()

간단한 문제인데 82퍼의 벽에 막혀 엄청나게 틀렸다.

profile
개발자 지망생

0개의 댓글