結果

問題 No.3 ビットすごろく
コンテスト
ユーザー Kohei
提出日時 2026-10-11 13:08:10
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 37 ms / 5,000 ms
+ 152µs
コード長 337 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 704 ms
コンパイル使用メモリ 80,700 KB
実行使用メモリ 65,408 KB
最終ジャッジ日時 2026-10-11 13:08:30
合計ジャッジ時間 3,684 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import deque
N = int(input())
dist = [-1]*(N + 1)
dist[1] = 1
que = deque()
que.append(1)
while que:
    pos = que.popleft()
    b = pos.bit_count()
    for j in [-b, b]:
        nex = pos + j
        if 1 <= nex <= N and dist[nex] == -1:
            dist[nex] = dist[pos] + 1
            que.append(nex)
print(dist[-1])
0