結果

問題 No.3 ビットすごろく
ユーザー nidosino
提出日時 2017-06-02 04:20:16
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 953 bytes
コンパイル時間 72 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-09-21 21:44:46
合計ジャッジ時間 1,979 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

MAX_STEP = 100000


def my_bin(x):
    return bin(x).count("1")

if __name__ == '__main__':
    A = int(input())
    bit_one_list = list(map(my_bin, range(1, A + 1)))
    din_list = [MAX_STEP] * A
    now_step = 0
    hohaba = 0
    step_count = 0
    step_queue = [now_step]
    while len(step_queue) > 0:
        now_step = step_queue.pop(0)
        hohaba = bit_one_list[now_step]
        if now_step + hohaba + 1 <= A and step_count + 1 < din_list[now_step + hohaba]:
            step_count += 1
            step_queue.append(now_step + hohaba)
            din_list[now_step + hohaba] = step_count + 1
        elif now_step - hohaba + 1 > 0 and step_count + 1 < din_list[now_step - hohaba]:
            step_count += 1
            step_queue.append(now_step - hohaba)
            din_list[now_step - hohaba] = step_count + 1
    if din_list[A - 1] != MAX_STEP:
        print(din_list[A - 1])
    else:
        print(-1)
0