結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
c-yan
|
| 提出日時 | 2020-12-10 00:29:31 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 410 bytes |
| コンパイル時間 | 82 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 11,008 KB |
| 最終ジャッジ日時 | 2024-09-19 06:58:37 |
| 合計ジャッジ時間 | 1,922 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | RE * 33 |
ソースコード
from collections import deque
N = int(input())
INF = 10 ** 12
t = [INF] * N
t[0] = 0
q = deque([0])
while q:
a = q.popleft()
d = bin(a + 1).count(1)
if a - d > 0 and t[a - d] > t[a] + 1:
t[a - d] = t[a] + 1
q.append(a - d)
if a + d < N and t[a + d] > t[a] + 1:
t[a + d] = t[a] + 1
q.append(a + d)
if t[N - 1] == INF:
print(-1)
else:
print(t[N - 1])
c-yan