結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-01-11 19:19:32 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 466 bytes |
| コンパイル時間 | 499 ms |
| コンパイル使用メモリ | 82,356 KB |
| 実行使用メモリ | 162,188 KB |
| 最終ジャッジ日時 | 2024-11-25 08:12:01 |
| 合計ジャッジ時間 | 165,182 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 WA * 1 TLE * 27 |
ソースコード
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)