結果

問題 No.3 ビットすごろく
ユーザー shiccocsan
提出日時 2016-12-01 20:33:26
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 45 ms / 5,000 ms
コード長 400 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-07-01 08:10:43
合計ジャッジ時間 2,331 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

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