結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  Twizz | 
| 提出日時 | 2017-02-24 13:33:14 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 44 ms / 5,000 ms | 
| コード長 | 468 bytes | 
| コンパイル時間 | 181 ms | 
| コンパイル使用メモリ | 12,800 KB | 
| 実行使用メモリ | 11,648 KB | 
| 最終ジャッジ日時 | 2024-07-01 08:20:17 | 
| 合計ジャッジ時間 | 2,225 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 33 | 
ソースコード
N=int(input())
list={1:1}
que=[(1,1)]
loc=1
while True:
    cnt=que[0][1]+1
    loc=que[0][0]
    mov=(bin(loc)).count("1")
    if loc+mov<=N:
        if loc+mov not in list:
            list[loc+mov]=cnt
            que.append((loc+mov,cnt))
    if loc-mov>=1:
        if loc-mov not in list:
            list[loc-mov]=cnt
            que.append((loc-mov,cnt))
    que.pop(0)
    if que==[]:
        break
if N not in list:
    print(-1)
else:
    print(list[N])
            
            
            
        