結果

問題 No.3 ビットすごろく
ユーザー bellangeldindonbellangeldindon
提出日時 2017-06-01 22:20:48
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 355 bytes
コンパイル時間 42 ms
コンパイル使用メモリ 7,104 KB
実行使用メモリ 6,472 KB
最終ジャッジ日時 2023-10-21 20:17:39
合計ジャッジ時間 1,629 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,396 KB
testcase_01 AC 11 ms
6,396 KB
testcase_02 AC 10 ms
6,396 KB
testcase_03 AC 13 ms
6,396 KB
testcase_04 AC 12 ms
6,396 KB
testcase_05 AC 18 ms
6,396 KB
testcase_06 AC 13 ms
6,396 KB
testcase_07 AC 11 ms
6,396 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 18 ms
6,396 KB
testcase_13 AC 12 ms
6,396 KB
testcase_14 AC 24 ms
6,408 KB
testcase_15 AC 30 ms
6,424 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 12 ms
6,396 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 10 ms
6,396 KB
testcase_22 AC 25 ms
6,408 KB
testcase_23 AC 31 ms
6,424 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 11 ms
6,396 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 11 ms
6,396 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def bitone(n):
	cnt = 0
	m = n
	while m > 0:
		if m % 2 == 1:
			cnt += 1
		m = m / 2
	return cnt

def sugoroku(n):
	now = 1
	cnt = 1
	history = []
	while now < n:
		b = bitone(now)
		cnt += 1
		if now + b > n:
			now -= b
		else:
			now += b
		if now in history:
			return -1
		else:
			history.append(now)
	
	return cnt

print sugoroku(int(raw_input()))
0