結果

問題 No.3 ビットすごろく
ユーザー nidosinonidosino
提出日時 2017-06-02 04:22:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 951 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 11,836 KB
実行使用メモリ 10,336 KB
最終ジャッジ日時 2023-10-21 20:19:47
合計ジャッジ時間 2,323 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 29 ms
10,008 KB
testcase_03 AC 33 ms
10,096 KB
testcase_04 WA -
testcase_05 AC 38 ms
10,216 KB
testcase_06 AC 34 ms
10,108 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 38 ms
10,204 KB
testcase_13 AC 33 ms
10,080 KB
testcase_14 AC 41 ms
10,292 KB
testcase_15 AC 45 ms
10,332 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 29 ms
10,008 KB
testcase_22 AC 42 ms
10,292 KB
testcase_23 AC 45 ms
10,336 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

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
        if 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