얼렁뚱땅 백준 문제풀이
[백준 문제풀이] 얼렁뚱땅 14248번 점프 점프 풀이
MOSTAR
2022. 4. 8. 20:16
사실 김민지는 지금 김민지의 기쁨을 위해
쉬운 문제만 풀고 있습니다. 푸하하하핳
import sys
from collections import deque
n = int(sys.stdin.readline())
array = list(map(int,sys.stdin.readline().split()))
start = int(sys.stdin.readline())
visited = [False] * len(array)
q = deque()
q.append(start)
while q :
now = q.popleft()
if visited[now-1] == False :
visited[now-1] = True
jump=array[now-1]
dx = [jump,-jump]
for i in range(2) :
nx = now + dx[i]
if 1<=nx<=n :
q.append(nx)
count = 0
for i in range(len(visited)) :
if visited[i] :
count += 1
print(count)