結果

問題 No.3 ビットすごろく
ユーザー NagisaNagisa
提出日時 2016-01-30 04:08:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 35 ms / 5,000 ms
コード長 603 bytes
コンパイル時間 106 ms
コンパイル使用メモリ 10,980 KB
実行使用メモリ 9,052 KB
最終ジャッジ日時 2023-09-13 23:39:43
合計ジャッジ時間 2,346 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,796 KB
testcase_01 AC 16 ms
7,824 KB
testcase_02 AC 18 ms
7,820 KB
testcase_03 AC 22 ms
8,440 KB
testcase_04 AC 18 ms
7,988 KB
testcase_05 AC 26 ms
8,548 KB
testcase_06 AC 21 ms
8,400 KB
testcase_07 AC 18 ms
8,168 KB
testcase_08 AC 24 ms
8,688 KB
testcase_09 AC 28 ms
8,572 KB
testcase_10 AC 31 ms
8,908 KB
testcase_11 AC 30 ms
8,580 KB
testcase_12 AC 28 ms
8,476 KB
testcase_13 AC 21 ms
8,428 KB
testcase_14 AC 31 ms
9,016 KB
testcase_15 AC 35 ms
8,940 KB
testcase_16 AC 33 ms
8,864 KB
testcase_17 AC 35 ms
8,860 KB
testcase_18 AC 20 ms
8,344 KB
testcase_19 AC 34 ms
8,864 KB
testcase_20 AC 18 ms
7,852 KB
testcase_21 AC 16 ms
7,792 KB
testcase_22 AC 31 ms
9,028 KB
testcase_23 AC 34 ms
9,052 KB
testcase_24 AC 35 ms
8,952 KB
testcase_25 AC 33 ms
8,864 KB
testcase_26 AC 16 ms
7,768 KB
testcase_27 AC 20 ms
8,340 KB
testcase_28 AC 32 ms
8,872 KB
testcase_29 AC 28 ms
8,564 KB
testcase_30 AC 17 ms
7,864 KB
testcase_31 AC 17 ms
7,768 KB
testcase_32 AC 27 ms
8,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

goal = int(input())
visited = {1:1}
tsugi = {1:1}
sonotsugi = {}

while tsugi:
    if goal in visited:
        break
    for node in tsugi:
        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.update({p:tsugi[node]+1})
            sonotsugi.update({p:tsugi[node]+1})
        if m not in visited and 0 < m < goal+1:
            visited.update({m:tsugi[node]+1})
            sonotsugi.update({m:tsugi[node]+1})
    tsugi = sonotsugi
    sonotsugi = {}

print(visited[goal] if goal in visited else -1)
0