結果

問題 No.3 ビットすごろく
ユーザー 12354865271235486527
提出日時 2019-11-27 11:47:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 55 ms / 5,000 ms
コード長 414 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 10,912 KB
実行使用メモリ 9,320 KB
最終ジャッジ日時 2023-09-14 01:30:33
合計ジャッジ時間 2,686 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
8,904 KB
testcase_01 AC 23 ms
8,924 KB
testcase_02 AC 23 ms
9,040 KB
testcase_03 AC 31 ms
8,972 KB
testcase_04 AC 25 ms
8,980 KB
testcase_05 AC 39 ms
9,216 KB
testcase_06 AC 31 ms
9,044 KB
testcase_07 AC 28 ms
9,060 KB
testcase_08 AC 36 ms
9,156 KB
testcase_09 AC 44 ms
9,280 KB
testcase_10 AC 49 ms
9,208 KB
testcase_11 AC 43 ms
9,212 KB
testcase_12 AC 39 ms
9,052 KB
testcase_13 AC 29 ms
8,940 KB
testcase_14 AC 49 ms
9,320 KB
testcase_15 AC 54 ms
9,304 KB
testcase_16 AC 53 ms
9,172 KB
testcase_17 AC 54 ms
9,148 KB
testcase_18 AC 29 ms
9,000 KB
testcase_19 AC 55 ms
9,196 KB
testcase_20 AC 24 ms
8,932 KB
testcase_21 AC 22 ms
9,096 KB
testcase_22 AC 48 ms
9,156 KB
testcase_23 AC 55 ms
9,276 KB
testcase_24 AC 54 ms
9,224 KB
testcase_25 AC 55 ms
9,152 KB
testcase_26 AC 23 ms
8,924 KB
testcase_27 AC 29 ms
8,968 KB
testcase_28 AC 52 ms
9,156 KB
testcase_29 AC 43 ms
9,184 KB
testcase_30 AC 22 ms
9,044 KB
testcase_31 AC 23 ms
8,924 KB
testcase_32 AC 41 ms
9,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from queue import Queue

def culc_num_of_bits(bits):
    return bin(bits).count('1')

N = int(input())
m = [-1 for i in range(N+1)]
m[1] = 1

Q = Queue()
Q.put(1)

while not Q.empty():
    c = Q.get()
    b = culc_num_of_bits(c)
    if c + b <= N and m[c + b] == -1:
        m[c + b] = m[c] + 1
        Q.put(c + b)
    if c - b > 0 and m[c - b] == -1:
        m[c - b] = m[c] + 1
        Q.put(c - b)

print(m[N])
0