結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,828 KB
testcase_01 AC 16 ms
7,828 KB
testcase_02 AC 16 ms
7,784 KB
testcase_03 AC 28 ms
7,772 KB
testcase_04 AC 19 ms
7,836 KB
testcase_05 AC 47 ms
8,320 KB
testcase_06 AC 30 ms
7,868 KB
testcase_07 AC 22 ms
7,808 KB
testcase_08 AC 41 ms
8,232 KB
testcase_09 AC 58 ms
8,264 KB
testcase_10 AC 66 ms
8,480 KB
testcase_11 AC 55 ms
8,240 KB
testcase_12 AC 47 ms
8,272 KB
testcase_13 AC 25 ms
7,828 KB
testcase_14 AC 65 ms
8,452 KB
testcase_15 AC 77 ms
8,520 KB
testcase_16 AC 74 ms
8,428 KB
testcase_17 AC 73 ms
8,496 KB
testcase_18 AC 23 ms
7,732 KB
testcase_19 AC 76 ms
8,404 KB
testcase_20 AC 18 ms
7,812 KB
testcase_21 AC 16 ms
7,732 KB
testcase_22 AC 65 ms
8,392 KB
testcase_23 AC 75 ms
8,440 KB
testcase_24 AC 77 ms
8,492 KB
testcase_25 AC 78 ms
8,428 KB
testcase_26 AC 16 ms
7,752 KB
testcase_27 AC 27 ms
7,900 KB
testcase_28 AC 69 ms
8,396 KB
testcase_29 AC 54 ms
8,392 KB
testcase_30 AC 16 ms
7,832 KB
testcase_31 AC 16 ms
7,812 KB
testcase_32 AC 52 ms
8,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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