結果

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

ソースコード

diff #

from collections import deque

# N = int(input())
N = 2343
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
        break

    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