結果

問題 No.3 ビットすごろく
ユーザー shiccocsanshiccocsan
提出日時 2016-12-01 20:33:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 400 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 10,964 KB
実行使用メモリ 8,556 KB
最終ジャッジ日時 2023-09-14 00:13:31
合計ジャッジ時間 2,140 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,804 KB
testcase_01 AC 17 ms
7,804 KB
testcase_02 AC 18 ms
7,772 KB
testcase_03 AC 19 ms
7,808 KB
testcase_04 AC 17 ms
7,904 KB
testcase_05 AC 23 ms
8,368 KB
testcase_06 AC 19 ms
7,876 KB
testcase_07 AC 18 ms
7,904 KB
testcase_08 AC 22 ms
8,364 KB
testcase_09 AC 25 ms
8,480 KB
testcase_10 AC 27 ms
8,520 KB
testcase_11 AC 24 ms
8,312 KB
testcase_12 AC 22 ms
8,292 KB
testcase_13 AC 18 ms
7,964 KB
testcase_14 AC 27 ms
8,344 KB
testcase_15 AC 29 ms
8,556 KB
testcase_16 AC 28 ms
8,520 KB
testcase_17 AC 29 ms
8,464 KB
testcase_18 AC 19 ms
7,772 KB
testcase_19 AC 29 ms
8,464 KB
testcase_20 AC 17 ms
7,824 KB
testcase_21 AC 16 ms
7,804 KB
testcase_22 AC 27 ms
8,520 KB
testcase_23 AC 28 ms
8,464 KB
testcase_24 AC 28 ms
8,532 KB
testcase_25 AC 28 ms
8,552 KB
testcase_26 AC 16 ms
7,896 KB
testcase_27 AC 19 ms
7,804 KB
testcase_28 AC 27 ms
8,552 KB
testcase_29 AC 24 ms
8,492 KB
testcase_30 AC 16 ms
7,860 KB
testcase_31 AC 16 ms
7,876 KB
testcase_32 AC 23 ms
8,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
bn = [format(x, 'b').count('1') for x in range(n + 1)]

l = [9999999] * (n + 1)
l[1] = 1
tmp = [1]
while tmp:
    next_tmp = []
    for i in tmp:
        for j in (i - bn[i], i + bn[i]):
            if 0 < j <= n:
                if l[j] > l[i] + 1:
                    l[j] = l[i] + 1
                    next_tmp.append(j)
    tmp = next_tmp

print(l[n] if l[n] < 9999999 else -1)
0