結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2023-06-14 21:03:51 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 577 bytes |
コンパイル時間 | 397 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 274,480 KB |
最終ジャッジ日時 | 2024-06-23 03:10:17 |
合計ジャッジ時間 | 15,881 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 TLE * 1 -- * 17 |
ソースコード
def min_moves(N: int) -> int: from collections import deque queue = deque([(1, 0)]) visited = set() while queue: pos, moves = queue.popleft() if pos == N: return moves + 1 visited.add(pos) next_moves = bin(pos).count('1') if pos + next_moves <= N and pos + next_moves not in visited: queue.append((pos + next_moves, moves + 1)) if pos - next_moves > 0 and pos - next_moves not in visited: queue.append((pos - next_moves, moves + 1)) return -1 print(min_moves(int(input())))