結果

問題 No.3 ビットすごろく
ユーザー daleksprinterdaleksprinter
提出日時 2018-08-12 08:53:41
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 623 bytes
コンパイル時間 74 ms
コンパイル使用メモリ 7,124 KB
実行使用メモリ 15,504 KB
最終ジャッジ日時 2023-10-24 14:29:17
合計ジャッジ時間 11,705 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 14 ms
7,200 KB
testcase_03 AC 232 ms
7,332 KB
testcase_04 WA -
testcase_05 AC 3,125 ms
8,544 KB
testcase_06 AC 254 ms
7,336 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 TLE -
testcase_10 -- -
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 #

import Queue

n = int(input())

def chkdigit(n):
	count = 0
	if n == 0:
		return 0
	while n:
		if n%2 == 1:
			count += 1
		n /= 2

	return count

q = Queue.Queue()

q.put([1,0])

isvisited = [-1 for i in range(n)]
isvisited[0] = 0

while not q.empty() :

	tmp = q.get()

	if tmp[0] == n:
		print isvisited
		print tmp[1] + 1
		quit()

	a = chkdigit(tmp[0])
	if 0 < tmp[0] + a < n+1 and isvisited[tmp[0]-1+a] == -1 :
		isvisited[tmp[0]-1] = tmp[1] + 1
		q.put([tmp[0] + a, tmp[1] + 1])

	if 0 < tmp[0] -a < n+1 and isvisited[tmp[0]-1-a] == -1:
		isvisited[tmp[0]-1] = tmp[1] + 1
		q.put([tmp[0] - a, tmp[1] + 1])

print -1
0