結果

問題 No.3 ビットすごろく
ユーザー dashi_dragonsdashi_dragons
提出日時 2017-02-13 21:35:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 515 bytes
コンパイル時間 83 ms
コンパイル使用メモリ 10,780 KB
実行使用メモリ 9,004 KB
最終ジャッジ日時 2023-08-28 15:42:00
合計ジャッジ時間 2,216 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 15 ms
7,812 KB
testcase_02 AC 14 ms
7,748 KB
testcase_03 AC 18 ms
8,228 KB
testcase_04 WA -
testcase_05 AC 24 ms
8,576 KB
testcase_06 AC 19 ms
8,284 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 23 ms
8,616 KB
testcase_13 AC 18 ms
8,336 KB
testcase_14 AC 28 ms
8,788 KB
testcase_15 AC 32 ms
8,788 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 28 ms
8,668 KB
testcase_23 AC 32 ms
8,728 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def bitcnt(N):
	cnt = 0

	while N != 0:
		if N % 2 == 1:
			cnt += 1
		N = N // 2
	return cnt

N = int(input())

loc = 1
queue = [1]
list = {1:0}
cnt = 0

while True:

	loc = queue[0]
	cnt += 1	
	mov = bitcnt(loc)

	if loc + mov <= N:
		if loc + mov not in list:
			list[loc + mov] = cnt
			queue.append(loc + mov)

	if loc - mov >= 1:
		if loc - mov not in list:
			list[loc - mov] = cnt
			queue.append(loc - mov)
	queue.remove(loc)

	if queue == []:
		break

if N not in list:
	print(-1)
else:
	print(list[N])		
0