結果

問題 No.3 ビットすごろく
ユーザー gigurururugigurururu
提出日時 2014-11-04 15:46:12
言語 Python2
(2.7.18)
結果
AC  
実行時間 86 ms / 5,000 ms
コード長 310 bytes
コンパイル時間 557 ms
コンパイル使用メモリ 6,692 KB
実行使用メモリ 6,848 KB
最終ジャッジ日時 2023-09-13 22:53:08
合計ジャッジ時間 3,607 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
6,716 KB
testcase_01 AC 14 ms
6,668 KB
testcase_02 AC 14 ms
6,768 KB
testcase_03 AC 32 ms
6,804 KB
testcase_04 AC 20 ms
6,672 KB
testcase_05 AC 52 ms
6,668 KB
testcase_06 AC 33 ms
6,772 KB
testcase_07 AC 25 ms
6,752 KB
testcase_08 AC 44 ms
6,612 KB
testcase_09 AC 63 ms
6,684 KB
testcase_10 AC 72 ms
6,696 KB
testcase_11 AC 59 ms
6,648 KB
testcase_12 AC 51 ms
6,820 KB
testcase_13 AC 29 ms
6,672 KB
testcase_14 AC 71 ms
6,720 KB
testcase_15 AC 84 ms
6,676 KB
testcase_16 AC 79 ms
6,788 KB
testcase_17 AC 82 ms
6,848 KB
testcase_18 AC 27 ms
6,760 KB
testcase_19 AC 84 ms
6,824 KB
testcase_20 AC 19 ms
6,656 KB
testcase_21 AC 14 ms
6,768 KB
testcase_22 AC 73 ms
6,652 KB
testcase_23 AC 85 ms
6,816 KB
testcase_24 AC 86 ms
6,668 KB
testcase_25 AC 86 ms
6,828 KB
testcase_26 AC 14 ms
6,784 KB
testcase_27 AC 30 ms
6,676 KB
testcase_28 AC 81 ms
6,672 KB
testcase_29 AC 61 ms
6,768 KB
testcase_30 AC 16 ms
6,716 KB
testcase_31 AC 16 ms
6,764 KB
testcase_32 AC 57 ms
6,764 KB
権限があれば一括ダウンロードができます

ソースコード

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