結果

問題 No.3 ビットすごろく
ユーザー kanoekakihitokanoekakihito
提出日時 2016-09-24 00:42:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 573 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 10,904 KB
実行使用メモリ 8,600 KB
最終ジャッジ日時 2023-08-11 06:16:07
合計ジャッジ時間 2,403 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,848 KB
testcase_01 AC 15 ms
7,956 KB
testcase_02 AC 15 ms
7,884 KB
testcase_03 AC 18 ms
8,172 KB
testcase_04 AC 16 ms
7,848 KB
testcase_05 AC 25 ms
8,252 KB
testcase_06 AC 19 ms
8,236 KB
testcase_07 AC 17 ms
7,820 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 24 ms
8,336 KB
testcase_13 AC 19 ms
8,300 KB
testcase_14 AC 33 ms
8,352 KB
testcase_15 AC 40 ms
8,540 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 18 ms
8,212 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 15 ms
7,888 KB
testcase_22 AC 34 ms
8,356 KB
testcase_23 AC 41 ms
8,420 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 15 ms
7,852 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 16 ms
7,824 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())

prev = [[1, []]]
fastest = dict()
end_flag = False
c = 1

while len(prev) != 0:
	next = []
	for p in prev:
		if p[0] == n:
			print(c)
			end_flag = True
			break
		b = bin(p[0])[2:].count("1")
		if b + p[0] > n:
			next_place = p[0] - b 
		else:
			next_place = p[0] + b
		if next_place not in fastest or fastest[next_place] <= c:
			if 1 <= next_place <= n and not next_place in p[1]:
				fastest[next_place] = c
				next.append([next_place,  p[1] + [p[0]]])
	if end_flag:
		break
	
	c += 1
	prev = sorted(next, key = lambda x: x[0])
		
else:
	print(-1)
0