結果

問題 No.3 ビットすごろく
コンテスト
ユーザー tookunn_1213
提出日時 2015-08-16 13:03:01
言語 PyPy2
(7.3.20)
結果
TLE  
実行時間 -
コード長 467 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 214 ms
コンパイル使用メモリ 77,268 KB
最終ジャッジ日時 2025-12-03 16:15:03
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 9 TLE * 1 -- * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N = int(raw_input())
queue = [1,1]
path = [False for i in range(N)]
ans = -1
while len(queue) > 0:
	now,count= queue.pop(0),queue.pop(0)
	path[now - 1] = True
	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]):
		queue.append(now + s)
		queue.append(count + 1)
	if not(next2 <= 0 or path[next2 - 1]):
		queue.append(now - s)
		queue.append(count + 1)
print ans
0