-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14226.py
More file actions
20 lines (20 loc) · 799 Bytes
/
Copy path14226.py
File metadata and controls
20 lines (20 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from collections import deque
s = int(input())
visited = [[0] * (s+1) for _ in range(s+1)]
def bfs():
queue = deque()
queue.append((0, 1, 0))
while(queue):
cnt, screen, clipboard = queue.popleft()
if screen == s:
return cnt
if not visited[screen][screen]:
visited[screen][screen] = True
queue.append((cnt+1, screen, screen))
if clipboard and screen + clipboard <= s and not visited[screen+clipboard][clipboard]:
visited[screen+clipboard][clipboard] = True
queue.append((cnt+1, screen + clipboard, clipboard))
if screen-1 >= 0 and not visited[screen-1][clipboard]:
visited[screen-1][clipboard] = True
queue.append((cnt+1, screen-1, clipboard))
print(bfs())