結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
sepa38
|
| 提出日時 | 2023-04-23 21:05:45 |
| 言語 | PyPy3 (8.0.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 39 ms / 5,000 ms |
| + 893µs | |
| コード長 | 382 bytes |
| 記録 | |
| コンパイル時間 | 73 ms |
| コンパイル使用メモリ | 81,024 KB |
| 実行使用メモリ | 72,448 KB |
| 最終ジャッジ日時 | 2026-09-21 01:24:17 |
| 合計ジャッジ時間 | 3,126 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
from collections import deque
n = int(input())
inf = 1 << 30
dist = [inf] * (n + 1)
dist[1] = 1
d = deque([1])
while d:
u = d.popleft()
x = bin(u).count("1")
if u + x <= n and dist[u+x] > dist[u] + 1:
dist[u+x] = dist[u] + 1
d.append(u+x)
if 0 < u - x and dist[u-x] > dist[u] + 1:
dist[u-x] = dist[u] + 1
d.append(u-x)
print(dist[n] if dist[n] < inf else -1)
sepa38