結果

問題 No.3 ビットすごろく
ユーザー leno
提出日時 2017-08-29 16:36:27
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 606 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-11-06 09:40:33
合計ジャッジ時間 13,915 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import copy


def bfs(N):
    queue = [1]
    visited = []
    cnt = 0
    while queue:
        label = copy.deepcopy(queue)
        queue.clear()
        cnt += 1
        while label:
            pl = label.pop(0)
            if pl == N:
                return cnt
            if pl < 1 or N + 1 < pl:
                continue
            if pl in visited:
                continue
            visited += [pl]
            tmp = int(str(bin(pl)).count('1'))
            queue += [pl+tmp, pl-tmp]
    return -1


if __name__ == '__main__':
    N = int(input())
    print(bfs(N))
0