結果

問題 No.3 ビットすごろく
ユーザー daleksprinterdaleksprinter
提出日時 2018-08-12 08:39:23
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 563 bytes
コンパイル時間 848 ms
コンパイル使用メモリ 7,148 KB
実行使用メモリ 7,584 KB
最終ジャッジ日時 2023-10-24 14:29:02
合計ジャッジ時間 2,941 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
7,184 KB
testcase_01 AC 14 ms
7,184 KB
testcase_02 AC 14 ms
7,184 KB
testcase_03 AC 17 ms
7,260 KB
testcase_04 AC 15 ms
7,196 KB
testcase_05 AC 21 ms
7,376 KB
testcase_06 AC 18 ms
7,268 KB
testcase_07 AC 17 ms
7,224 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 21 ms
7,372 KB
testcase_13 AC 17 ms
7,244 KB
testcase_14 AC 24 ms
7,484 KB
testcase_15 AC 26 ms
7,560 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 16 ms
7,232 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 14 ms
7,184 KB
testcase_22 AC 24 ms
7,488 KB
testcase_23 AC 26 ms
7,564 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 14 ms
7,184 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 15 ms
7,184 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

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 = [0 for i in range(n)]

while not q.empty() :
	tmp = q.get()

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

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

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

print -1

0