結果

問題 No.3 ビットすごろく
ユーザー seiichi
提出日時 2020-11-19 16:42:14
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 838 bytes
コンパイル時間 106 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 22,400 KB
最終ジャッジ日時 2024-07-23 10:05:20
合計ジャッジ時間 6,893 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 TLE * 1 -- * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N = int(input())
queue = deque([{"count":1, "position":1}])
passed_position = []
result = -1

while queue:
    q = queue.popleft()
    current_position = q["position"]
    current_count = q["count"]

    if current_position == N:
        result = current_count

    if current_position < N:
        passed_position.append(current_position)
        steps = bin(current_position).count("1")

        forward_step = current_position + steps
        backward_step = current_position - steps

        if forward_step not in passed_position and 1 < forward_step <= N:
            queue.append({"count":current_count+1, "position":forward_step})
        if backward_step not in passed_position and 1 < backward_step <= N:
            queue.append({"count":current_count+1, "position":backward_step})

print(result)
0