結果

問題 No.3 ビットすごろく
コンテスト
ユーザー mahiro
提出日時 2020-01-11 19:20:02
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
TLE  
実行時間 -
コード長 466 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 540 ms
コンパイル使用メモリ 20,572 KB
実行使用メモリ 15,232 KB
最終ジャッジ日時 2026-05-19 20:38:41
合計ジャッジ時間 7,789 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 TLE * 1 -- * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N = int(input())

spaces = [float("inf")] * (N + 1)
bits = {i: str(bin(i))[2:].count("1") for i in range(N + 1)}
spaces[1] = 0

visited = [False] * (N + 1)


def dfs(i, p):
    if not 0 < i < N + 1:
        return None
    if visited[i]:
        return None
    visited[i] = True
    spaces[i] = min(spaces[i], p)
    dfs(i + bits[i], p+1)
    dfs(i - bits[i], p+1)
    visited[i] = False


dfs(1, 1)

ans = -1 if spaces[N] == float("inf") else spaces[N]
print(ans)
0