結果
| 問題 | 
                            No.3 ビットすごろく
                             | 
                    
| コンテスト | |
| ユーザー | 
                             maburoe
                         | 
                    
| 提出日時 | 2019-05-28 13:39:21 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 584 bytes | 
| コンパイル時間 | 208 ms | 
| コンパイル使用メモリ | 12,544 KB | 
| 実行使用メモリ | 11,264 KB | 
| 最終ジャッジ日時 | 2024-09-17 15:39:15 | 
| 合計ジャッジ時間 | 1,786 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge6 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 14 WA * 4 RE * 15 | 
ソースコード
goal = int(input())
# goal_1bit_num = bin(goal)
# print(goal_1bit_num.count('1'))
stepped = set()
maybe_answers = set()
def step(position, count):
    if position in stepped:
        return
    else:
        stepped.add(position)
    if position not in range(1, goal + 1):
        return
    if position == goal:
        maybe_answers.add(count)
        return
    bit1_num = bin(position).count('1')
    step(position + bit1_num, count + 1)
    step(position - bit1_num, count + 1)
step(1, 1)
if len(maybe_answers) == 0:
    print('-1')
else:
    print(min(maybe_answers))
            
            
            
        
            
maburoe