結果

問題 No.3 ビットすごろく
コンテスト
ユーザー gigurururu
提出日時 2014-11-04 15:46:12
言語 PyPy2
(7.3.20)
コンパイル:
pypy2 -m py_compile _filename_
実行:
/usr/bin/pypy2 Main.pyc
結果
AC  
実行時間 94 ms / 5,000 ms
+ 378µs
コード長 310 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 90 ms
コンパイル使用メモリ 80,640 KB
実行使用メモリ 85,120 KB
最終ジャッジ日時 2026-07-17 07:38:53
合計ジャッジ時間 5,039 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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