結果

問題 No.3 ビットすごろく
ユーザー htkbhtkb
提出日時 2019-02-09 12:33:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 4,236 ms / 5,000 ms
コード長 480 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 10,968 KB
実行使用メモリ 9,672 KB
最終ジャッジ日時 2023-09-14 11:10:48
合計ジャッジ時間 52,692 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,992 KB
testcase_01 AC 15 ms
7,952 KB
testcase_02 AC 15 ms
7,828 KB
testcase_03 AC 249 ms
8,604 KB
testcase_04 AC 36 ms
8,168 KB
testcase_05 AC 1,168 ms
8,948 KB
testcase_06 AC 302 ms
8,624 KB
testcase_07 AC 110 ms
8,308 KB
testcase_08 AC 740 ms
8,724 KB
testcase_09 AC 1,972 ms
9,112 KB
testcase_10 AC 2,819 ms
9,344 KB
testcase_11 AC 1,656 ms
9,072 KB
testcase_12 AC 1,124 ms
8,864 KB
testcase_13 AC 180 ms
8,444 KB
testcase_14 AC 2,657 ms
9,308 KB
testcase_15 AC 4,129 ms
9,596 KB
testcase_16 AC 3,567 ms
9,508 KB
testcase_17 AC 4,024 ms
9,604 KB
testcase_18 AC 138 ms
8,444 KB
testcase_19 AC 4,236 ms
9,644 KB
testcase_20 AC 26 ms
8,208 KB
testcase_21 AC 15 ms
7,864 KB
testcase_22 AC 2,713 ms
9,268 KB
testcase_23 AC 4,215 ms
9,620 KB
testcase_24 AC 4,213 ms
9,576 KB
testcase_25 AC 4,155 ms
9,672 KB
testcase_26 AC 16 ms
7,888 KB
testcase_27 AC 214 ms
8,484 KB
testcase_28 AC 3,418 ms
9,496 KB
testcase_29 AC 1,700 ms
9,096 KB
testcase_30 AC 16 ms
7,836 KB
testcase_31 AC 17 ms
7,936 KB
testcase_32 AC 1,440 ms
9,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)
N = int(input())
a = list((bin(i).count("1") for i in range(N+1)))
inf = float("inf")
dp = [inf, 1] + [inf]*(N+100)


def dfs(i, steps):
    if i == N:
        return
    back, forward = i-a[i], i+a[i]
    steps += 1
    if dp[back] > steps:
        dp[back] = steps
        dfs(back, steps)
    if N >= forward and dp[forward] > steps:
        dp[forward] = steps
        dfs(forward, steps)


dfs(1, 1)
print(dp[N] if dp[N] < inf else -1)
0