結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  ytft | 
| 提出日時 | 2022-11-01 00:11:53 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 116 ms / 5,000 ms | 
| コード長 | 424 bytes | 
| コンパイル時間 | 408 ms | 
| コンパイル使用メモリ | 82,048 KB | 
| 実行使用メモリ | 79,232 KB | 
| 最終ジャッジ日時 | 2024-07-08 11:36:12 | 
| 合計ジャッジ時間 | 4,636 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 33 | 
ソースコード
import sys,queue
input=lambda:sys.stdin.readline().rstrip()
def count(N):
	return bin(N).count('1')
def con(a):
	return [a+count(a+1),a-count(a+1)]
N=int(input())
dist=[float('inf') for i in range(N)]
dist[0]=1
q=queue.SimpleQueue()
q.put(0)
while not q.empty():
	temp=q.get()
	for i in con(temp):
		if 0<=i<N and dist[i]>dist[temp]+1:
			dist[i]=dist[temp]+1
			q.put(i)
print(dist[N-1] if dist[N-1]!=float('inf') else -1)
            
            
            
        