結果

問題 No.3 ビットすごろく
ユーザー maburoemaburoe
提出日時 2019-05-28 13:35:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 685 bytes
コンパイル時間 126 ms
コンパイル使用メモリ 11,816 KB
実行使用メモリ 10,504 KB
最終ジャッジ日時 2023-10-17 18:22:50
合計ジャッジ時間 2,680 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,032 KB
testcase_01 AC 32 ms
10,032 KB
testcase_02 AC 30 ms
10,032 KB
testcase_03 AC 33 ms
10,260 KB
testcase_04 AC 31 ms
10,040 KB
testcase_05 AC 36 ms
10,396 KB
testcase_06 AC 33 ms
10,264 KB
testcase_07 AC 31 ms
10,092 KB
testcase_08 WA -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 37 ms
10,392 KB
testcase_13 AC 34 ms
10,236 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 31 ms
10,108 KB
testcase_19 RE -
testcase_20 WA -
testcase_21 AC 30 ms
10,032 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 29 ms
10,032 KB
testcase_27 WA -
testcase_28 RE -
testcase_29 RE -
testcase_30 WA -
testcase_31 AC 30 ms
10,036 KB
testcase_32 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

goal = int(input())

# goal_1bit_num = bin(goal)
# print(goal_1bit_num.count('1'))

stepped = set()
maybe_answers = set()


def step(position, count):
    if position in stepped:
        return
    else:
        stepped.add(position)

    if position not in range(1, goal + 1):
        return

    if len(maybe_answers) > 0 and count < min(maybe_answers):
        return

    if position == goal:
        maybe_answers.add(count)
        return

    position_bin = bin(position)
    step(position + position_bin.count('1'), count + 1)
    step(position - position_bin.count('1'), count + 1)


step(1, 1)

if len(maybe_answers) == 0:
    print('-1')
else:
    print(min(maybe_answers))
0