結果

問題 No.3 ビットすごろく
ユーザー aimBULLaimBULL
提出日時 2016-06-17 01:25:29
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 551 bytes
コンパイル時間 60 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 19,352 KB
最終ジャッジ日時 2024-04-17 23:00:43
合計ジャッジ時間 8,503 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
6,784 KB
testcase_01 AC 13 ms
6,784 KB
testcase_02 AC 14 ms
6,784 KB
testcase_03 AC 72 ms
6,912 KB
testcase_04 AC 25 ms
6,784 KB
testcase_05 AC 839 ms
7,936 KB
testcase_06 AC 78 ms
6,912 KB
testcase_07 AC 44 ms
6,656 KB
testcase_08 AC 295 ms
7,296 KB
testcase_09 TLE -
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N = input()
table = [9999999999] * (N + 1)

q = deque()
q.append([1,1])

while len(q) > 0:
	p = q.popleft()
	current = p[0]
	cost = p[1]
	if current == N:
		print cost
		exit()
	
	next = (current + bin(current).count('1'))
	if 0 < next and next <= N:
		if cost + 1 <= table[next]:
			q.append([next, cost + 1])
			table[next] = cost + 1
	
	prev = (current - bin(current).count('1'))
	if 0 < prev:
		if cost + 1 <= table[prev]:
			q.append([current - bin(current).count('1'), cost + 1])
			table[prev] = cost + 1
print -1
0