結果

問題 No.3 ビットすごろく
ユーザー lloyz
提出日時 2022-01-09 22:04:43
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 61 ms / 5,000 ms
コード長 548 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-11-14 10:34:13
合計ジャッジ時間 2,464 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n = int(input())
Que = deque([(1, 1)])
seen = set([1])
ans = -1
while Que:
    curr, cnt = Que.popleft()
    if curr == n:
        ans = cnt
        break
    cc = curr
    res = 0
    while cc != 0:
        res += cc % 2
        cc //= 2
    if curr - res >= 1 and curr - res not in seen:
        seen.add(curr - res)
        Que.append((curr - res, cnt + 1))
    if curr + res <= n and curr + res not in seen:
        seen.add(curr + res)
        Que.append((curr + res, cnt + 1))
print(ans)
0