結果

問題 No.3 ビットすごろく
ユーザー 炭酸水炭酸水
提出日時 2022-04-02 15:27:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 41 ms / 5,000 ms
コード長 677 bytes
コンパイル時間 155 ms
コンパイル使用メモリ 10,900 KB
実行使用メモリ 9,380 KB
最終ジャッジ日時 2023-08-13 18:47:36
合計ジャッジ時間 2,183 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,868 KB
testcase_01 AC 15 ms
7,916 KB
testcase_02 AC 15 ms
7,716 KB
testcase_03 AC 21 ms
8,516 KB
testcase_04 AC 16 ms
8,172 KB
testcase_05 AC 28 ms
8,580 KB
testcase_06 AC 22 ms
8,372 KB
testcase_07 AC 19 ms
8,316 KB
testcase_08 AC 26 ms
8,628 KB
testcase_09 AC 32 ms
8,680 KB
testcase_10 AC 35 ms
8,908 KB
testcase_11 AC 30 ms
8,708 KB
testcase_12 AC 28 ms
8,728 KB
testcase_13 AC 20 ms
8,316 KB
testcase_14 AC 37 ms
8,788 KB
testcase_15 AC 40 ms
9,224 KB
testcase_16 AC 38 ms
9,096 KB
testcase_17 AC 39 ms
9,348 KB
testcase_18 AC 19 ms
8,336 KB
testcase_19 AC 41 ms
9,368 KB
testcase_20 AC 17 ms
8,224 KB
testcase_21 AC 14 ms
7,840 KB
testcase_22 AC 35 ms
8,796 KB
testcase_23 AC 40 ms
9,212 KB
testcase_24 AC 41 ms
9,380 KB
testcase_25 AC 40 ms
9,156 KB
testcase_26 AC 14 ms
7,764 KB
testcase_27 AC 20 ms
8,528 KB
testcase_28 AC 38 ms
9,252 KB
testcase_29 AC 30 ms
8,660 KB
testcase_30 AC 15 ms
7,836 KB
testcase_31 AC 16 ms
7,856 KB
testcase_32 AC 30 ms
8,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())

a = [float("inf") for _ in range(n * 2 + 10)]
a[1] = 1

b = [0 for _ in range(n * 2 + 10)]
b[0] = 1

s = []
s_1 = [1,1]
s.append(s_1)
while len(s) != 0 and b[n] != 1:
    s.sort()
    t = s.pop(0)
    u = str(bin(t[1])).count("1")
    b[t[1]] = 1
    if t[1] < n:
        if b[t[1] + u] != 1 and a[t[1]] + 1 < a[t[1] + u]:
            a[t[1] + u] = a[t[1]] + 1
            s_1 = [a[t[1]] + 1 , t[1] + u]
            s.append(s_1)
        if b[t[1] - u] != 1 and a[t[1]] + 1 < a[t[1] - u]:
            a[t[1] - u] = a[t[1]] + 1
            s_1 = [a[t[1]] + 1 , t[1] - u]
            s.append(s_1)


if a[n] == float("inf"):
    print(-1)
else:
    print(a[n])
0