結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  nisizawa | 
| 提出日時 | 2017-12-07 20:20:34 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 43 ms / 5,000 ms | 
| コード長 | 451 bytes | 
| コンパイル時間 | 84 ms | 
| コンパイル使用メモリ | 12,416 KB | 
| 実行使用メモリ | 11,008 KB | 
| 最終ジャッジ日時 | 2024-07-01 08:52:35 | 
| 合計ジャッジ時間 | 2,258 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 33 | 
ソースコード
from collections import deque
n = int(input())
ls = [-1] * n
queue = deque([0])
ls[0] = 1
while len(queue) > 0:
    x = queue.popleft()
    i = ls[x]
    if x == n - 1:
        print(i)
        break
    
    d = bin(x + 1).count('1')
    if 0 <= x + d < n and ls[x + d] == -1:
        queue.append(x + d)
        ls[x + d] = i + 1
    if 0 <= x - d < n and ls[x - d] == -1:
        queue.append(x - d)
        ls[x - d] = i + 1
else:
    print(-1)
            
            
            
        