結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  tookunn_1213 | 
| 提出日時 | 2015-08-16 13:05:52 | 
| 言語 | Python2 (2.7.18) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 28 ms / 5,000 ms | 
| コード長 | 506 bytes | 
| コンパイル時間 | 39 ms | 
| コンパイル使用メモリ | 7,040 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-07-01 07:28:55 | 
| 合計ジャッジ時間 | 1,619 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 33 | 
ソースコード
N = int(raw_input())
queue = [1,1]
path = [False for i in range(N)]
ans = -1
path[0] = True
while len(queue) > 0:
	now,count= queue.pop(0),queue.pop(0)
	if now == N:
		ans = count
		break
	s = str(bin(now)).count('1')
	if s == 0:continue
	next1 = now + s
	next2 = now - s
	if not(next1 > N or path[next1 - 1]):
		path[next1 - 1] = True
		queue.append(next1)
		queue.append(count + 1)
	if not(next2 <= 0 or path[next2 - 1]):
		path[next2 - 1] = True
		queue.append(next2)
		queue.append(count + 1)
print ans
            
            
            
        