結果
問題 | No.3 ビットすごろく |
ユーザー |
![]() |
提出日時 | 2023-04-23 21:05:45 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 76 ms / 5,000 ms |
コード長 | 382 bytes |
コンパイル時間 | 374 ms |
コンパイル使用メモリ | 82,688 KB |
実行使用メモリ | 70,400 KB |
最終ジャッジ日時 | 2024-11-08 02:50:06 |
合計ジャッジ時間 | 3,582 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
from collections import dequen = int(input())inf = 1 << 30dist = [inf] * (n + 1)dist[1] = 1d = 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] + 1d.append(u+x)if 0 < u - x and dist[u-x] > dist[u] + 1:dist[u-x] = dist[u] + 1d.append(u-x)print(dist[n] if dist[n] < inf else -1)