結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 12 ms
6,392 KB
testcase_03 AC 15 ms
6,392 KB
testcase_04 WA -
testcase_05 AC 19 ms
6,392 KB
testcase_06 AC 14 ms
6,392 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 19 ms
6,392 KB
testcase_13 AC 14 ms
6,392 KB
testcase_14 AC 26 ms
6,404 KB
testcase_15 AC 32 ms
6,420 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 11 ms
6,392 KB
testcase_22 AC 25 ms
6,404 KB
testcase_23 AC 32 ms
6,420 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 11 ms
6,392 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
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 = []
	flag = False
	while now < n:
		b = bitone(now)
		cnt += b
		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