結果
| 問題 | 
                            No.3 ビットすごろく
                             | 
                    
| コンテスト | |
| ユーザー | 
                             いまり💣🍠
                         | 
                    
| 提出日時 | 2024-06-07 06:14:00 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 506 bytes | 
| コンパイル時間 | 474 ms | 
| コンパイル使用メモリ | 82,048 KB | 
| 実行使用メモリ | 64,128 KB | 
| 最終ジャッジ日時 | 2024-12-25 05:56:19 | 
| 合計ジャッジ時間 | 3,426 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 18 WA * 15 | 
ソースコード
from collections import deque
N = int(input())
todo = deque()
todo.append(0)
counts = [0] * N
counts[0] = 1
while len(todo) > 0:
    i = todo.pop()
    if i == N - 1:
        print(counts[i])
        exit()
    back = i - (i + 1).bit_count()
    front = i + (i + 1).bit_count()
    if back >= 0 and counts[back] == 0:
        counts[back] = counts[i] + 1
        todo.append(back)
    if front < N and counts[front] == 0:
        counts[front] = counts[i] + 1
        todo.append(front)
        
print(-1)
            
            
            
        
            
いまり💣🍠