結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,072 KB
testcase_01 AC 29 ms
10,072 KB
testcase_02 AC 29 ms
10,072 KB
testcase_03 AC 32 ms
10,300 KB
testcase_04 AC 29 ms
10,116 KB
testcase_05 AC 35 ms
10,436 KB
testcase_06 AC 32 ms
10,304 KB
testcase_07 AC 30 ms
10,148 KB
testcase_08 WA -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 35 ms
10,432 KB
testcase_13 AC 31 ms
10,276 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 31 ms
10,156 KB
testcase_19 RE -
testcase_20 WA -
testcase_21 AC 30 ms
10,072 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 29 ms
10,072 KB
testcase_27 WA -
testcase_28 RE -
testcase_29 RE -
testcase_30 WA -
testcase_31 AC 29 ms
10,076 KB
testcase_32 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

goal = int(input())

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

stepped = set()
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 position == goal:
        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(answers) == 0:
    print('-1')
else:
    print(min(answers))
0