結果

問題 No.3 ビットすごろく
ユーザー seiichi seiichi
提出日時 2020-11-19 17:08:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 925 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 10,808 KB
実行使用メモリ 8,892 KB
最終ジャッジ日時 2023-09-30 16:23:37
合計ジャッジ時間 2,103 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,904 KB
testcase_01 AC 15 ms
7,792 KB
testcase_02 AC 15 ms
7,884 KB
testcase_03 AC 16 ms
8,352 KB
testcase_04 AC 16 ms
8,244 KB
testcase_05 AC 16 ms
8,544 KB
testcase_06 AC 16 ms
8,352 KB
testcase_07 AC 16 ms
8,440 KB
testcase_08 WA -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 16 ms
8,688 KB
testcase_13 AC 16 ms
8,368 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 16 ms
8,392 KB
testcase_19 RE -
testcase_20 WA -
testcase_21 AC 15 ms
7,820 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 15 ms
7,796 KB
testcase_27 WA -
testcase_28 RE -
testcase_29 RE -
testcase_30 WA -
testcase_31 AC 15 ms
7,816 KB
testcase_32 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

# 再帰呼び出し

N = int(input())
queue = {"count":1, "position":1}
passed_position = {1}

def get_count(q):
    current_position = q["position"]
    current_count = q["count"]

    if current_position == N:
        return current_count
    elif current_position < N:
        steps = bin(current_position).count("1")

        forward_position = current_position + steps
        backward_position = current_position - steps

        if forward_position not in passed_position and 1 < forward_position <= N:
            passed_position.add(forward_position)
            return get_count({"count":current_count+1, "position":forward_position})
        if backward_position not in passed_position and 1 < backward_position <= N:
            passed_position.add(backward_position)
            return get_count({"count":current_count+1, "position":backward_position})

result = get_count(queue)
print(result if result else -1)
0