結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-04-05 10:21:16 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 409 bytes |
| コンパイル時間 | 272 ms |
| コンパイル使用メモリ | 82,148 KB |
| 実行使用メモリ | 70,812 KB |
| 最終ジャッジ日時 | 2024-12-30 12:45:44 |
| 合計ジャッジ時間 | 3,503 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 WA * 23 |
ソースコード
from collections import deque
n = int(input())
inf = 10**10
dp = [inf]*(n+2)
dp[1] = 0
q = deque([1])
while q:
now = q.popleft()
b = bin(now).count("1")
if now+b <= n and dp[now+b] > dp[now]+1:
dp[now+b] = dp[now]+1
q.append(now+b)
if now-b > 0 and dp[now-b] > dp[now]+1:
dp[now-b] = dp[now]+1
q.append(now-b)
ans = dp[n]
if ans == inf:
ans = -1
print(ans)