結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2019-08-31 11:03:53 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 41 ms / 5,000 ms |
コード長 | 372 bytes |
コンパイル時間 | 307 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-07-01 09:29:14 |
合計ジャッジ時間 | 2,336 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
from collections import deque N = int(input()) visited = [False] * (N + 1) visited[1] = True Q = deque([(1, 1)]) while Q: n, c = Q.popleft() if n == N: print(c) quit() d = bin(n).count("1") for nn in (n + d, n - d): if 0 < nn <= N and not visited[nn]: visited[nn] = True Q.append((nn, c + 1)) print(-1)