結果

問題 No.3 ビットすごろく
ユーザー bellangeldindonbellangeldindon
提出日時 2019-04-26 10:05:34
言語 Python2
(2.7.18)
結果
AC  
実行時間 40 ms / 5,000 ms
コード長 614 bytes
コンパイル時間 797 ms
コンパイル使用メモリ 6,708 KB
実行使用メモリ 6,576 KB
最終ジャッジ日時 2023-09-14 01:17:19
合計ジャッジ時間 2,628 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
5,948 KB
testcase_01 AC 11 ms
6,076 KB
testcase_02 AC 11 ms
5,880 KB
testcase_03 AC 17 ms
6,152 KB
testcase_04 AC 13 ms
5,872 KB
testcase_05 AC 26 ms
6,268 KB
testcase_06 AC 17 ms
5,976 KB
testcase_07 AC 15 ms
6,076 KB
testcase_08 AC 23 ms
6,192 KB
testcase_09 AC 30 ms
6,224 KB
testcase_10 AC 34 ms
6,404 KB
testcase_11 AC 29 ms
6,396 KB
testcase_12 AC 25 ms
6,268 KB
testcase_13 AC 16 ms
6,196 KB
testcase_14 AC 33 ms
6,444 KB
testcase_15 AC 38 ms
6,564 KB
testcase_16 AC 36 ms
6,296 KB
testcase_17 AC 37 ms
6,384 KB
testcase_18 AC 15 ms
6,008 KB
testcase_19 AC 39 ms
6,428 KB
testcase_20 AC 12 ms
6,000 KB
testcase_21 AC 10 ms
5,856 KB
testcase_22 AC 34 ms
6,320 KB
testcase_23 AC 39 ms
6,408 KB
testcase_24 AC 40 ms
6,576 KB
testcase_25 AC 38 ms
6,472 KB
testcase_26 AC 11 ms
5,936 KB
testcase_27 AC 16 ms
6,096 KB
testcase_28 AC 36 ms
6,536 KB
testcase_29 AC 29 ms
6,328 KB
testcase_30 AC 12 ms
5,852 KB
testcase_31 AC 11 ms
6,076 KB
testcase_32 AC 28 ms
6,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def countbit(n):
	m = n
	cnt = 0
	while m != 0:
		if m % 2 == 1: cnt += 1
		m = m / 2
	return cnt
N = int(raw_input())
passed = [False]
board = [-1]
for i in range(0, N):
	passed.append(True)
	board.append(-1)
queue = [[1, 1, passed]]
while queue != []:
	now = queue.pop(0)
	newpassed = now[2]
	if now[2][now[0]]:
		newpassed[now[0]] = False
		move = countbit(now[0])
		if board[now[0]] == -1 or board[now[0]] > now[1]:
			board[now[0]] = now[1]
		if now[0] + move <= N:
			queue.append([now[0]+move, now[1]+1, newpassed])
		if now[0] - move >= 1:
			queue.append([now[0]-move, now[1]+1, newpassed])
print board[N]
0