結果

問題 No.3 ビットすごろく
ユーザー gigurururu
提出日時 2014-11-04 15:46:12
言語 Python2
(2.7.18)
結果
AC  
実行時間 90 ms / 5,000 ms
コード長 310 bytes
コンパイル時間 343 ms
コンパイル使用メモリ 6,944 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-07-01 07:05:46
合計ジャッジ時間 2,978 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

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
0