結果

問題 No.3 ビットすごろく
ユーザー ayame_pyayame_py
提出日時 2015-10-06 02:35:03
言語 Python2
(2.7.18)
結果
AC  
実行時間 66 ms / 5,000 ms
コード長 541 bytes
コンパイル時間 516 ms
コンパイル使用メモリ 6,700 KB
実行使用メモリ 8,872 KB
最終ジャッジ日時 2023-09-13 23:25:47
合計ジャッジ時間 3,079 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
6,628 KB
testcase_01 AC 14 ms
6,700 KB
testcase_02 AC 14 ms
6,464 KB
testcase_03 AC 28 ms
7,012 KB
testcase_04 AC 18 ms
6,792 KB
testcase_05 AC 41 ms
7,436 KB
testcase_06 AC 29 ms
7,096 KB
testcase_07 AC 23 ms
6,776 KB
testcase_08 AC 36 ms
7,336 KB
testcase_09 AC 51 ms
8,132 KB
testcase_10 AC 56 ms
8,272 KB
testcase_11 AC 47 ms
7,916 KB
testcase_12 AC 41 ms
7,432 KB
testcase_13 AC 25 ms
6,896 KB
testcase_14 AC 56 ms
8,392 KB
testcase_15 AC 65 ms
8,680 KB
testcase_16 AC 60 ms
8,480 KB
testcase_17 AC 63 ms
8,632 KB
testcase_18 AC 24 ms
6,916 KB
testcase_19 AC 66 ms
8,872 KB
testcase_20 AC 17 ms
6,764 KB
testcase_21 AC 15 ms
6,668 KB
testcase_22 AC 56 ms
8,408 KB
testcase_23 AC 65 ms
8,864 KB
testcase_24 AC 66 ms
8,768 KB
testcase_25 AC 65 ms
8,664 KB
testcase_26 AC 15 ms
6,552 KB
testcase_27 AC 26 ms
6,860 KB
testcase_28 AC 60 ms
8,624 KB
testcase_29 AC 47 ms
7,880 KB
testcase_30 AC 15 ms
6,640 KB
testcase_31 AC 16 ms
6,644 KB
testcase_32 AC 45 ms
7,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
from Queue import Queue
INF = 1e9+7
N = int(raw_input())

def bc(x):
    return bin(x).count("1")

to_list = []
for i in range(1, N+1):
	bci=bc(i)
	temp_to = []
	if i-bci > 0:
		temp_to.append(i-bci-1)
	if i+bci < N+1:
		temp_to.append(i+bci-1)
	to_list.append(temp_to)

#bfsをするよ!
chk = [INF for _ in range(N)]
chk[0] = 1
que = Queue()
que.put(0)
while not que.empty():
	q = que.get()
	for i in to_list[q]:
		if chk[i] == INF:
			chk[i]=chk[q]+1
			que.put(i)

if chk[N-1] == INF:
	print '-1'
else:
	print chk[N-1]
0