結果

問題 No.3 ビットすごろく
ユーザー ynyn
提出日時 2015-06-11 17:00:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 873 ms / 5,000 ms
コード長 586 bytes
コンパイル時間 1,053 ms
コンパイル使用メモリ 10,920 KB
実行使用メモリ 9,660 KB
最終ジャッジ日時 2023-09-13 23:13:33
合計ジャッジ時間 13,408 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,936 KB
testcase_01 AC 16 ms
7,772 KB
testcase_02 AC 16 ms
7,804 KB
testcase_03 AC 68 ms
8,488 KB
testcase_04 AC 21 ms
8,188 KB
testcase_05 AC 262 ms
9,092 KB
testcase_06 AC 80 ms
8,548 KB
testcase_07 AC 39 ms
8,192 KB
testcase_08 AC 174 ms
8,836 KB
testcase_09 AC 430 ms
9,232 KB
testcase_10 AC 610 ms
9,376 KB
testcase_11 AC 362 ms
9,116 KB
testcase_12 AC 250 ms
8,844 KB
testcase_13 AC 55 ms
8,448 KB
testcase_14 AC 574 ms
9,464 KB
testcase_15 AC 847 ms
9,652 KB
testcase_16 AC 740 ms
9,556 KB
testcase_17 AC 841 ms
9,604 KB
testcase_18 AC 43 ms
8,524 KB
testcase_19 AC 873 ms
9,464 KB
testcase_20 AC 18 ms
8,392 KB
testcase_21 AC 15 ms
7,772 KB
testcase_22 AC 583 ms
9,452 KB
testcase_23 AC 873 ms
9,660 KB
testcase_24 AC 868 ms
9,568 KB
testcase_25 AC 862 ms
9,612 KB
testcase_26 AC 15 ms
7,848 KB
testcase_27 AC 62 ms
8,440 KB
testcase_28 AC 721 ms
9,492 KB
testcase_29 AC 369 ms
9,200 KB
testcase_30 AC 16 ms
7,828 KB
testcase_31 AC 16 ms
7,980 KB
testcase_32 AC 317 ms
9,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

B = []
counter = []
routes = [[1]]
visited = [1]
turns = -1

for x in range(0, N) :
	B.append(bin(x+1))
	counter.append(B[x].count('1'))

while routes :
	grid = routes.pop(0)
	grid_a = grid[:]
	grid_b = grid[:]

	present = grid[-1]

	s1 = present + counter[present-1]
	s2 = present - counter[present-1]

	if present == N :
		turns = len(grid)

	if s1 not in visited and 0 < s1 <= N :
		visited.append(s1)
		grid_a.append(s1)
		routes.append(grid_a)

	if s2 not in visited and 0 < s2 <= N :
		visited.append(s2)
		grid_b.append(s2)
		routes.append(grid_b)

print(turns)
0