結果

問題 No.3 ビットすごろく
ユーザー mationaruzoumationaruzou
提出日時 2020-05-01 20:26:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 31 ms / 5,000 ms
コード長 324 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 10,800 KB
実行使用メモリ 8,968 KB
最終ジャッジ日時 2023-09-14 01:43:09
合計ジャッジ時間 2,206 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,660 KB
testcase_01 AC 18 ms
8,568 KB
testcase_02 AC 19 ms
8,648 KB
testcase_03 AC 22 ms
8,548 KB
testcase_04 AC 20 ms
8,472 KB
testcase_05 AC 25 ms
8,752 KB
testcase_06 AC 21 ms
8,664 KB
testcase_07 AC 21 ms
8,656 KB
testcase_08 AC 23 ms
8,624 KB
testcase_09 AC 27 ms
8,672 KB
testcase_10 AC 28 ms
8,760 KB
testcase_11 AC 25 ms
8,788 KB
testcase_12 AC 25 ms
8,692 KB
testcase_13 AC 21 ms
8,632 KB
testcase_14 AC 28 ms
8,740 KB
testcase_15 AC 30 ms
8,752 KB
testcase_16 AC 29 ms
8,792 KB
testcase_17 AC 31 ms
8,912 KB
testcase_18 AC 21 ms
8,496 KB
testcase_19 AC 30 ms
8,908 KB
testcase_20 AC 20 ms
8,472 KB
testcase_21 AC 19 ms
8,524 KB
testcase_22 AC 28 ms
8,796 KB
testcase_23 AC 31 ms
8,776 KB
testcase_24 AC 30 ms
8,968 KB
testcase_25 AC 31 ms
8,908 KB
testcase_26 AC 19 ms
8,672 KB
testcase_27 AC 21 ms
8,696 KB
testcase_28 AC 29 ms
8,744 KB
testcase_29 AC 26 ms
8,660 KB
testcase_30 AC 19 ms
8,564 KB
testcase_31 AC 19 ms
8,468 KB
testcase_32 AC 26 ms
8,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
n = int(input())

l = [-1]*n

l[0] = 1
q = deque([0])

while q:
    x = q.popleft()
    bx = bin(x+1).count("1")
    if x+bx < n and l[x+bx] == -1:
        l[x+bx] = l[x]+1
        q.append(x+bx)
    if x-bx >= 0 and l[x-bx] == -1:
        l[x-bx] = l[x]+1
        q.append(x-bx)

print(l[n-1])
0