結果

問題 No.3 ビットすごろく
ユーザー papinniepapinnie
提出日時 2019-08-06 20:14:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 878 bytes
コンパイル時間 1,155 ms
コンパイル使用メモリ 10,856 KB
実行使用メモリ 13,724 KB
最終ジャッジ日時 2023-09-25 18:09:08
合計ジャッジ時間 31,130 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 16 ms
7,844 KB
testcase_03 AC 464 ms
8,504 KB
testcase_04 WA -
testcase_05 AC 2,162 ms
8,692 KB
testcase_06 AC 560 ms
8,468 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2,028 ms
8,652 KB
testcase_13 AC 314 ms
8,376 KB
testcase_14 AC 4,462 ms
9,196 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10000)

N = int(input())

def get_total(x):
    return sum(map(int,list("{0:b}".format(x))))

already = set()
ables = set()

def go_next(now, mv_count):
    already.add(now)
    mv_count += 1
    step = get_total(now) # 進める数
    #print("now", now, "mv_count", mv_count, "step", step)
    
    go_m = now + step  # 進む先
    if go_m == N:
        # goal
        ables.add(mv_count)
    if  go_m < N:
        go_next(go_m, mv_count)
    
    back_m = now - step # 戻る先
    if back_m not in already:
        # 行ったことのあるところなら行かない
        if back_m > 0:
            go_next(back_m, mv_count)

if N == 1:
    print(1)
else:
    # 今=1, ステップ=1で再帰スタート
    go_next(1, 1)

if len(ables) > 0:
    print(ables)
    print(min(ables))
else:
    # 到達できなかった
    print(-1)
0