結果

問題 No.3 ビットすごろく
ユーザー daleksprinterdaleksprinter
提出日時 2018-08-12 09:44:19
言語 Python2
(2.7.18)
結果
AC  
実行時間 27 ms / 5,000 ms
コード長 370 bytes
コンパイル時間 453 ms
コンパイル使用メモリ 6,692 KB
実行使用メモリ 6,564 KB
最終ジャッジ日時 2023-09-14 01:04:58
合計ジャッジ時間 2,399 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,052 KB
testcase_01 AC 11 ms
6,016 KB
testcase_02 AC 12 ms
6,108 KB
testcase_03 AC 15 ms
6,108 KB
testcase_04 AC 12 ms
6,060 KB
testcase_05 AC 19 ms
6,156 KB
testcase_06 AC 15 ms
6,232 KB
testcase_07 AC 14 ms
6,200 KB
testcase_08 AC 17 ms
6,180 KB
testcase_09 AC 22 ms
6,368 KB
testcase_10 AC 24 ms
6,460 KB
testcase_11 AC 21 ms
6,208 KB
testcase_12 AC 19 ms
6,220 KB
testcase_13 AC 15 ms
6,204 KB
testcase_14 AC 23 ms
6,332 KB
testcase_15 AC 26 ms
6,332 KB
testcase_16 AC 25 ms
6,384 KB
testcase_17 AC 25 ms
6,412 KB
testcase_18 AC 14 ms
6,016 KB
testcase_19 AC 26 ms
6,532 KB
testcase_20 AC 12 ms
6,052 KB
testcase_21 AC 11 ms
5,996 KB
testcase_22 AC 23 ms
6,356 KB
testcase_23 AC 27 ms
6,336 KB
testcase_24 AC 26 ms
6,332 KB
testcase_25 AC 26 ms
6,564 KB
testcase_26 AC 12 ms
5,964 KB
testcase_27 AC 15 ms
6,012 KB
testcase_28 AC 24 ms
6,308 KB
testcase_29 AC 21 ms
6,344 KB
testcase_30 AC 11 ms
6,020 KB
testcase_31 AC 12 ms
6,028 KB
testcase_32 AC 20 ms
6,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())

visited = [-1 for i in range(n+1)]

q = [[1,1]]
visited[0] = 1
visited[1] = 1

while q :
	p , i = q.pop(0)
	if p == n:
		print i
		quit()

	a = p + bin(p).count("1")
	if a < n + 1 and visited[a] == -1:
		visited[a] = 1
		q.append([a,i + 1])

	b = p - bin(p).count("1")
	if 0 < b and visited[b] == -1:
		visited[b] = 1 
		q.append([b,i + 1])

print -1

0