Skip to content

Commit f15c532

Browse files
committed
🪙 S2-11060
1 parent f2b049a commit f15c532

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

🪙 S2/11060.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from collections import deque
2+
3+
n = int(input())
4+
arr = list(map(int, input().split()))
5+
visited = [0]*n
6+
7+
q = deque([(0, 0)])
8+
while q:
9+
depth, idx = q.popleft()
10+
if idx == n-1:
11+
print(depth)
12+
break
13+
for x in range(1, arr[idx]+1):
14+
if 0 < idx+x < n and not visited[idx+x]:
15+
visited[idx+x] = 1
16+
q.append((depth+1, idx+x))
17+
else:
18+
print(-1)

0 commit comments

Comments
 (0)