結果

問題 No.3 ビットすごろく
ユーザー Luoto-greenLuoto-green
提出日時 2017-07-31 18:46:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 27 ms / 5,000 ms
コード長 479 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 10,856 KB
実行使用メモリ 8,972 KB
最終ジャッジ日時 2023-09-14 00:47:15
合計ジャッジ時間 2,139 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,556 KB
testcase_01 AC 19 ms
8,548 KB
testcase_02 AC 18 ms
8,500 KB
testcase_03 AC 20 ms
8,504 KB
testcase_04 AC 19 ms
8,616 KB
testcase_05 AC 23 ms
8,612 KB
testcase_06 AC 21 ms
8,540 KB
testcase_07 AC 19 ms
8,556 KB
testcase_08 AC 21 ms
8,564 KB
testcase_09 AC 24 ms
8,736 KB
testcase_10 AC 25 ms
8,772 KB
testcase_11 AC 24 ms
8,712 KB
testcase_12 AC 22 ms
8,660 KB
testcase_13 AC 20 ms
8,504 KB
testcase_14 AC 25 ms
8,748 KB
testcase_15 AC 27 ms
8,856 KB
testcase_16 AC 26 ms
8,924 KB
testcase_17 AC 27 ms
8,964 KB
testcase_18 AC 20 ms
8,568 KB
testcase_19 AC 27 ms
8,852 KB
testcase_20 AC 18 ms
8,488 KB
testcase_21 AC 19 ms
8,656 KB
testcase_22 AC 25 ms
8,784 KB
testcase_23 AC 27 ms
8,956 KB
testcase_24 AC 27 ms
8,796 KB
testcase_25 AC 27 ms
8,832 KB
testcase_26 AC 19 ms
8,612 KB
testcase_27 AC 20 ms
8,620 KB
testcase_28 AC 26 ms
8,972 KB
testcase_29 AC 24 ms
8,692 KB
testcase_30 AC 18 ms
8,604 KB
testcase_31 AC 19 ms
8,668 KB
testcase_32 AC 24 ms
8,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
n = int(input())
def solve():
    A = deque([0]*(n+1))
    A[1]=1
    B = deque()
    B.append(1)
    while B:
        a = B.popleft()
        if n == a:
            return A[a]
        bc = bin(a).count("1")
        a1 = a + bc
        a2 = a - bc
        if 0<a1<=n and A[a1]==0:
            B.append(a1)
            A[a1]= A[a] + 1
        if 0<a2<=n and A[a2]==0:
            B.append(a2)
            A[a2]= A[a] + 1
    return -1
print(solve())
0