結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-04-05 10:20:06 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 409 bytes |
| コンパイル時間 | 377 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 65,792 KB |
| 最終ジャッジ日時 | 2024-12-30 12:44:12 |
| 合計ジャッジ時間 | 4,179 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 1 RE * 32 |
ソースコード
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:
do[now+b] = dp[now]+1
q.append(now+b)
if now-b > 0 and dp[now-b] > dp[now]+1:
do[now-b] = dp[now]+1
q.append(now-b)
ans = dp[n]
if ans == inf:
ans = -1
print(ans)