結果

問題 No.3 ビットすごろく
ユーザー howakurohowakuro
提出日時 2019-08-24 08:40:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 861 ms / 5,000 ms
コード長 538 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 10,828 KB
実行使用メモリ 8,852 KB
最終ジャッジ日時 2023-09-14 01:26:13
合計ジャッジ時間 12,281 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,576 KB
testcase_01 AC 19 ms
8,608 KB
testcase_02 AC 19 ms
8,472 KB
testcase_03 AC 70 ms
8,668 KB
testcase_04 AC 25 ms
8,560 KB
testcase_05 AC 258 ms
8,768 KB
testcase_06 AC 86 ms
8,632 KB
testcase_07 AC 42 ms
8,472 KB
testcase_08 AC 172 ms
8,672 KB
testcase_09 AC 420 ms
8,628 KB
testcase_10 AC 587 ms
8,792 KB
testcase_11 AC 356 ms
8,656 KB
testcase_12 AC 245 ms
8,616 KB
testcase_13 AC 55 ms
8,500 KB
testcase_14 AC 552 ms
8,704 KB
testcase_15 AC 839 ms
8,816 KB
testcase_16 AC 727 ms
8,692 KB
testcase_17 AC 811 ms
8,732 KB
testcase_18 AC 46 ms
8,604 KB
testcase_19 AC 854 ms
8,852 KB
testcase_20 AC 21 ms
8,652 KB
testcase_21 AC 19 ms
8,548 KB
testcase_22 AC 567 ms
8,764 KB
testcase_23 AC 853 ms
8,828 KB
testcase_24 AC 861 ms
8,772 KB
testcase_25 AC 832 ms
8,764 KB
testcase_26 AC 18 ms
8,444 KB
testcase_27 AC 63 ms
8,492 KB
testcase_28 AC 693 ms
8,836 KB
testcase_29 AC 365 ms
8,624 KB
testcase_30 AC 19 ms
8,552 KB
testcase_31 AC 19 ms
8,616 KB
testcase_32 AC 313 ms
8,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
def bitCount(n):
    return bin(n).count("1")

N = int(input())
Node = (1,1)
List = [1]
Queue = deque([Node])
while Queue:
    n,count = Queue.popleft()
    if n == N:
        print(count)
        exit()
    bit_count = bitCount(n)
    if n+bit_count <= N and n + bit_count not in List:
        List.append(n+bit_count)
        Queue.append((n+bit_count,count + 1))
    if n-bit_count > 1 and n - bit_count not in List:
        List.append(n-bit_count)
        Queue.append((n-bit_count,count + 1))
print(-1)
0