結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2014-11-04 15:46:12 |
| 言語 | PyPy2 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 173 ms / 5,000 ms |
| コード長 | 310 bytes |
| 記録 | |
| コンパイル時間 | 137 ms |
| コンパイル使用メモリ | 77,156 KB |
| 最終ジャッジ日時 | 2025-12-03 12:54:11 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
from Queue import Queue
n=input()
q=Queue()
q.put((1,1))
h=[False]*(n+1)
while not q.empty():
a,b=q.get()
if h[a]: continue
h[a]=True
if a==n:
print b
exit()
bit=bin(a).count("1")
if a+bit<=n: q.put((a+bit,b+1))
if a-bit>0: q.put((a-bit,b+1))
print -1