結果

問題 No.3 ビットすごろく
ユーザー dashi_dragonsdashi_dragons
提出日時 2017-02-13 20:42:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 715 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 8,520 KB
最終ジャッジ日時 2023-08-28 15:41:07
合計ジャッジ時間 2,406 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,844 KB
testcase_01 AC 16 ms
7,784 KB
testcase_02 AC 16 ms
7,788 KB
testcase_03 AC 17 ms
8,324 KB
testcase_04 AC 16 ms
7,792 KB
testcase_05 AC 18 ms
8,384 KB
testcase_06 AC 16 ms
8,220 KB
testcase_07 AC 16 ms
7,924 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 17 ms
8,280 KB
testcase_13 AC 16 ms
7,988 KB
testcase_14 AC 19 ms
8,360 KB
testcase_15 AC 19 ms
8,520 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 16 ms
8,372 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 15 ms
7,808 KB
testcase_22 AC 18 ms
8,324 KB
testcase_23 AC 19 ms
8,292 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 16 ms
7,988 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def bitcnt(N):
	
	cnt = 0
	while N != 0:
		cnt += N % 2
		N = N // 2

	return cnt

def move(loc,N):

	cnt = bitcnt(N)
	mov = loc

	while True:
		
		if cnt == 0:
			return -1

		if cnt + loc < N:
			mov = loc + cnt
			move(loc,N)


N = int(input())

if N < 1 or N > 10000:
	sys.exit()

loc = 1
cnt = 0
x = 1

pos = {}

while True:
	
	cnt = bitcnt(loc)
	#print('loc:'+str(loc))
	#print(pos)
	
	if loc not in pos:
		pos[loc] = 1
	
	if pos[loc] == 0:
		print('-1')
		break

	elif pos[loc] > 0:
		if loc + cnt < N:
			pos[loc] = -1
			loc += cnt
			x += 1
			continue

		elif loc + cnt == N:
			loc += cnt
			x += 1
			print(x)
			break

		else:
			pos[loc] = -1
	else:
		pos[loc] = 0
		loc -= cnt
		x += 1	
0