結果

問題 No.3 ビットすごろく
コンテスト
ユーザー T
提出日時 2025-11-19 14:00:04
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 39 ms / 5,000 ms
コード長 427 bytes
コンパイル時間 149 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2025-11-19 14:30:40
合計ジャッジ時間 2,619 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N = int(input())
dist = [-1] * (N + 1)
dist[1] = 1 #スタート位置
dig = deque([1])

while dig:
	s = dig.popleft()
	if (s == N):
		break
	else:
		c = bin(s).count("1")
		i = s + c
		h = s - c
		
	if ((i <= N) and (dist[i] == -1)):
		dist[i] = dist[s] + 1
		dig.append(i)
	else:
		pass
		
	if((h >= 1) and (dist[h] == -1)):
		dist[h] = dist[s] + 1
		dig.append(h)
	else:
		pass

print(dist[N])
0