結果

問題 No.3 ビットすごろく
ユーザー sangonanasangonana
提出日時 2021-04-08 11:23:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 31 ms / 5,000 ms
コード長 333 bytes
コンパイル時間 78 ms
コンパイル使用メモリ 10,600 KB
実行使用メモリ 8,896 KB
最終ジャッジ日時 2023-09-05 19:59:12
合計ジャッジ時間 2,249 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,540 KB
testcase_01 AC 21 ms
8,612 KB
testcase_02 AC 19 ms
8,592 KB
testcase_03 AC 22 ms
8,656 KB
testcase_04 AC 19 ms
8,444 KB
testcase_05 AC 25 ms
8,692 KB
testcase_06 AC 22 ms
8,516 KB
testcase_07 AC 20 ms
8,412 KB
testcase_08 AC 24 ms
8,700 KB
testcase_09 AC 27 ms
8,668 KB
testcase_10 AC 28 ms
8,840 KB
testcase_11 AC 27 ms
8,728 KB
testcase_12 AC 24 ms
8,636 KB
testcase_13 AC 21 ms
8,492 KB
testcase_14 AC 28 ms
8,800 KB
testcase_15 AC 31 ms
8,804 KB
testcase_16 AC 29 ms
8,752 KB
testcase_17 AC 30 ms
8,692 KB
testcase_18 AC 21 ms
8,624 KB
testcase_19 AC 30 ms
8,896 KB
testcase_20 AC 20 ms
8,444 KB
testcase_21 AC 19 ms
8,444 KB
testcase_22 AC 29 ms
8,700 KB
testcase_23 AC 31 ms
8,852 KB
testcase_24 AC 31 ms
8,852 KB
testcase_25 AC 31 ms
8,880 KB
testcase_26 AC 18 ms
8,512 KB
testcase_27 AC 22 ms
8,500 KB
testcase_28 AC 29 ms
8,692 KB
testcase_29 AC 26 ms
8,732 KB
testcase_30 AC 19 ms
8,616 KB
testcase_31 AC 19 ms
8,572 KB
testcase_32 AC 26 ms
8,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
n=int(input())
inf=10**9
dp=[inf]*n
dp[0]=1
queue=deque([0])
while queue:
	r=queue.popleft()
	one=bin(r+1).count("1")
	if r+one<n and dp[r+one]==inf:
		dp[r+one]=dp[r]+1
		queue.append(r+one)
	if 0<r-one and dp[r-one]==inf:
		dp[r-one]=dp[r]+1
		queue.append(r-one)
print(dp[-1] if dp[-1]!=inf else -1)	
0