結果

問題 No.3 ビットすごろく
ユーザー tmentaikotmentaiko
提出日時 2020-08-25 02:12:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 31 ms / 5,000 ms
コード長 420 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 10,876 KB
実行使用メモリ 8,960 KB
最終ジャッジ日時 2023-09-14 01:49:47
合計ジャッジ時間 2,231 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,520 KB
testcase_01 AC 21 ms
8,680 KB
testcase_02 AC 20 ms
8,632 KB
testcase_03 AC 22 ms
8,600 KB
testcase_04 AC 19 ms
8,680 KB
testcase_05 AC 25 ms
8,620 KB
testcase_06 AC 21 ms
8,656 KB
testcase_07 AC 21 ms
8,608 KB
testcase_08 AC 24 ms
8,636 KB
testcase_09 AC 27 ms
8,764 KB
testcase_10 AC 29 ms
8,728 KB
testcase_11 AC 27 ms
8,696 KB
testcase_12 AC 25 ms
8,596 KB
testcase_13 AC 22 ms
8,656 KB
testcase_14 AC 29 ms
8,924 KB
testcase_15 AC 31 ms
8,812 KB
testcase_16 AC 30 ms
8,960 KB
testcase_17 AC 31 ms
8,856 KB
testcase_18 AC 21 ms
8,576 KB
testcase_19 AC 31 ms
8,868 KB
testcase_20 AC 19 ms
8,528 KB
testcase_21 AC 19 ms
8,516 KB
testcase_22 AC 29 ms
8,796 KB
testcase_23 AC 30 ms
8,916 KB
testcase_24 AC 31 ms
8,752 KB
testcase_25 AC 31 ms
8,752 KB
testcase_26 AC 19 ms
8,688 KB
testcase_27 AC 21 ms
8,508 KB
testcase_28 AC 29 ms
8,828 KB
testcase_29 AC 26 ms
8,708 KB
testcase_30 AC 19 ms
8,624 KB
testcase_31 AC 19 ms
8,620 KB
testcase_32 AC 26 ms
8,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
def bc(x):
    return bin(x).count("1")
m=int(input())
st=[-1]*(m+1)
st[1]=1
q=deque()
q.append(1)
while len(q)!=0:
    cur = q.popleft()
    curbc=bc(cur)
    if cur+curbc<=m:
        if st[cur+curbc]==-1:
            st[cur+curbc]=st[cur]+1
            q.append(cur+curbc)
    if cur-curbc>=1 and st[cur-curbc]==-1:
        st[cur-curbc]=st[cur]+1
        q.append(cur-curbc)
print(st[m])
0