結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,008 KB
testcase_01 AC 32 ms
10,008 KB
testcase_02 AC 31 ms
10,008 KB
testcase_03 AC 33 ms
10,052 KB
testcase_04 AC 30 ms
10,012 KB
testcase_05 AC 32 ms
10,116 KB
testcase_06 AC 31 ms
10,056 KB
testcase_07 AC 30 ms
10,032 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 32 ms
10,108 KB
testcase_13 AC 31 ms
10,044 KB
testcase_14 AC 34 ms
10,136 KB
testcase_15 AC 35 ms
10,140 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 30 ms
10,036 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 30 ms
10,008 KB
testcase_22 AC 33 ms
10,136 KB
testcase_23 AC 35 ms
10,140 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 29 ms
10,008 KB
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
        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