結果

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

ソースコード

diff #

N = int(input())
queue = [1]
visited = set()
count = 0
while queue:
    count += 1
    n = []
    flg = False
    for i in queue:
        if i == N:
            print(count)
            flg = True
            break
        b1_num = bin(i).count('1')
        a = i + b1_num
        b = i - b1_num
        if a <= N and a not in visited:
            visited.add(a)
            n.append(a)
        if 1 < b and b not in visited:
            visited.add(b)
            n.append(b)
    queue = n
    if(flg):
        break
else:
    print(-1)
0