結果

問題 No.3 ビットすごろく
ユーザー NagisaNagisa
提出日時 2016-01-30 03:43:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 935 ms / 5,000 ms
コード長 563 bytes
コンパイル時間 308 ms
コンパイル使用メモリ 10,868 KB
実行使用メモリ 8,552 KB
最終ジャッジ日時 2023-09-13 23:40:29
合計ジャッジ時間 13,543 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,832 KB
testcase_01 AC 16 ms
7,824 KB
testcase_02 AC 16 ms
7,836 KB
testcase_03 AC 73 ms
7,836 KB
testcase_04 AC 22 ms
7,856 KB
testcase_05 AC 280 ms
8,176 KB
testcase_06 AC 85 ms
7,720 KB
testcase_07 AC 40 ms
7,792 KB
testcase_08 AC 184 ms
8,224 KB
testcase_09 AC 451 ms
8,288 KB
testcase_10 AC 637 ms
8,268 KB
testcase_11 AC 383 ms
8,276 KB
testcase_12 AC 268 ms
8,368 KB
testcase_13 AC 57 ms
7,940 KB
testcase_14 AC 597 ms
8,356 KB
testcase_15 AC 910 ms
8,408 KB
testcase_16 AC 791 ms
8,472 KB
testcase_17 AC 883 ms
8,372 KB
testcase_18 AC 47 ms
7,792 KB
testcase_19 AC 935 ms
8,552 KB
testcase_20 AC 20 ms
7,828 KB
testcase_21 AC 15 ms
7,776 KB
testcase_22 AC 611 ms
8,340 KB
testcase_23 AC 935 ms
8,416 KB
testcase_24 AC 935 ms
8,416 KB
testcase_25 AC 916 ms
8,356 KB
testcase_26 AC 16 ms
7,760 KB
testcase_27 AC 64 ms
7,912 KB
testcase_28 AC 758 ms
8,320 KB
testcase_29 AC 396 ms
8,132 KB
testcase_30 AC 15 ms
7,872 KB
testcase_31 AC 17 ms
7,924 KB
testcase_32 AC 341 ms
8,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

goal = int(input())
visited = [1]
tsugi1 = [1]
tsugi2 = []
count = 1

while tsugi1:
    if goal in visited:
        break
    while tsugi1:
        node = tsugi1.pop()
        p = node + int(bin(node).count("1"))
        m = node - int(bin(node).count("1"))
        if p not in visited and 0 < p < goal+1:
            visited.append(p)
            tsugi2.append(p)
        if m not in visited and 0 < m < goal+1:
            visited.append(m)
            tsugi2.append(m)
    tsugi1 = tsugi2
    tsugi2 = []
    count += 1

print(count if goal in visited else -1)
0