結果

問題 No.3 ビットすごろく
ユーザー tabataba
提出日時 2016-04-12 22:34:41
言語 Python2
(2.7.18)
結果
AC  
実行時間 25 ms / 5,000 ms
コード長 314 bytes
コンパイル時間 63 ms
コンパイル使用メモリ 6,572 KB
実行使用メモリ 6,464 KB
最終ジャッジ日時 2023-09-13 23:49:22
合計ジャッジ時間 1,990 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
5,968 KB
testcase_01 AC 12 ms
5,968 KB
testcase_02 AC 12 ms
6,044 KB
testcase_03 AC 14 ms
6,112 KB
testcase_04 AC 13 ms
6,044 KB
testcase_05 AC 18 ms
6,172 KB
testcase_06 AC 15 ms
6,144 KB
testcase_07 AC 13 ms
6,184 KB
testcase_08 AC 17 ms
6,188 KB
testcase_09 AC 20 ms
6,228 KB
testcase_10 AC 22 ms
6,284 KB
testcase_11 AC 19 ms
6,240 KB
testcase_12 AC 18 ms
6,396 KB
testcase_13 AC 14 ms
6,036 KB
testcase_14 AC 22 ms
6,364 KB
testcase_15 AC 24 ms
6,356 KB
testcase_16 AC 24 ms
6,428 KB
testcase_17 AC 24 ms
6,344 KB
testcase_18 AC 14 ms
6,192 KB
testcase_19 AC 25 ms
6,376 KB
testcase_20 AC 12 ms
5,980 KB
testcase_21 AC 11 ms
6,032 KB
testcase_22 AC 21 ms
6,456 KB
testcase_23 AC 24 ms
6,432 KB
testcase_24 AC 24 ms
6,464 KB
testcase_25 AC 24 ms
6,428 KB
testcase_26 AC 12 ms
6,060 KB
testcase_27 AC 14 ms
6,136 KB
testcase_28 AC 23 ms
6,312 KB
testcase_29 AC 19 ms
6,308 KB
testcase_30 AC 11 ms
6,080 KB
testcase_31 AC 11 ms
6,076 KB
testcase_32 AC 19 ms
6,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n=input()
p=[bin(x).count("1")for x in range(1,n+1)]
q=[9e9]*n
q[0]=1
step=1
nq=[0]
while len(nq):
	step+=1
	nnq=[]
	for i in nq:
		if i-p[i]>=0:
			if q[i-p[i]]>step:
				q[i-p[i]]=step
				nnq+=[i-p[i]]
		if i+p[i]<n:
			if q[i+p[i]]>step:
				q[i+p[i]]=step
				nnq+=[i+p[i]]
	nq=nnq
print[q[-1],-1][q[-1]==9e9]
0