結果

問題 No.3 ビットすごろく
ユーザー shobonvipshobonvip
提出日時 2022-03-11 20:38:58
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 112 ms / 5,000 ms
コード長 492 bytes
コンパイル時間 481 ms
コンパイル使用メモリ 87,076 KB
実行使用メモリ 77,676 KB
最終ジャッジ日時 2023-10-14 05:05:24
合計ジャッジ時間 6,192 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
71,220 KB
testcase_01 AC 94 ms
71,476 KB
testcase_02 AC 95 ms
71,220 KB
testcase_03 AC 109 ms
77,328 KB
testcase_04 AC 108 ms
77,252 KB
testcase_05 AC 110 ms
77,600 KB
testcase_06 AC 109 ms
77,244 KB
testcase_07 AC 110 ms
77,344 KB
testcase_08 AC 109 ms
77,268 KB
testcase_09 AC 111 ms
77,424 KB
testcase_10 AC 111 ms
77,296 KB
testcase_11 AC 109 ms
77,380 KB
testcase_12 AC 110 ms
77,664 KB
testcase_13 AC 109 ms
77,332 KB
testcase_14 AC 110 ms
77,384 KB
testcase_15 AC 111 ms
77,676 KB
testcase_16 AC 112 ms
77,516 KB
testcase_17 AC 109 ms
77,556 KB
testcase_18 AC 108 ms
77,372 KB
testcase_19 AC 111 ms
77,436 KB
testcase_20 AC 107 ms
77,024 KB
testcase_21 AC 95 ms
71,648 KB
testcase_22 AC 111 ms
77,496 KB
testcase_23 AC 109 ms
77,672 KB
testcase_24 AC 109 ms
77,668 KB
testcase_25 AC 112 ms
77,452 KB
testcase_26 AC 96 ms
71,456 KB
testcase_27 AC 107 ms
77,524 KB
testcase_28 AC 110 ms
77,396 KB
testcase_29 AC 110 ms
77,560 KB
testcase_30 AC 94 ms
71,628 KB
testcase_31 AC 96 ms
71,652 KB
testcase_32 AC 108 ms
77,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n = int(input())

tansaku = [0] * (n+1)
dp = [-1] * (n+1)
tansaku[1] = 1
dp[1] = 1

mada = deque([1])

while mada:
	i = mada.popleft()
	t = i
	cnt = 0
	while t:
		if t & 1:
			cnt += 1
		t >>= 1
	if i + cnt <= n:
		if tansaku[i + cnt] == 0:
			tansaku[i + cnt] = 1
			dp[i + cnt] = dp[i] + 1
			mada.append(i + cnt)
	if i - cnt >= 1:
		if tansaku[i - cnt] == 0:
			tansaku[i - cnt] = 1
			dp[i - cnt] = dp[i] + 1
			mada.append(i - cnt)

#print(dp)
print(dp[n])
0