結果

問題 No.3 ビットすごろく
ユーザー kohei2019kohei2019
提出日時 2021-02-02 21:02:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 25 ms / 5,000 ms
コード長 498 bytes
コンパイル時間 74 ms
コンパイル使用メモリ 10,860 KB
実行使用メモリ 8,932 KB
最終ジャッジ日時 2023-09-14 01:56:35
合計ジャッジ時間 1,760 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
8,516 KB
testcase_01 AC 15 ms
8,536 KB
testcase_02 AC 14 ms
8,484 KB
testcase_03 AC 18 ms
8,564 KB
testcase_04 AC 17 ms
8,528 KB
testcase_05 AC 22 ms
8,640 KB
testcase_06 AC 20 ms
8,580 KB
testcase_07 AC 16 ms
8,568 KB
testcase_08 AC 19 ms
8,704 KB
testcase_09 AC 22 ms
8,740 KB
testcase_10 AC 24 ms
8,788 KB
testcase_11 AC 21 ms
8,768 KB
testcase_12 AC 20 ms
8,660 KB
testcase_13 AC 16 ms
8,516 KB
testcase_14 AC 23 ms
8,780 KB
testcase_15 AC 24 ms
8,772 KB
testcase_16 AC 25 ms
8,788 KB
testcase_17 AC 25 ms
8,876 KB
testcase_18 AC 17 ms
8,572 KB
testcase_19 AC 25 ms
8,904 KB
testcase_20 AC 15 ms
8,536 KB
testcase_21 AC 15 ms
8,560 KB
testcase_22 AC 23 ms
8,764 KB
testcase_23 AC 25 ms
8,812 KB
testcase_24 AC 25 ms
8,904 KB
testcase_25 AC 25 ms
8,876 KB
testcase_26 AC 14 ms
8,480 KB
testcase_27 AC 17 ms
8,504 KB
testcase_28 AC 24 ms
8,932 KB
testcase_29 AC 21 ms
8,652 KB
testcase_30 AC 14 ms
8,624 KB
testcase_31 AC 14 ms
8,428 KB
testcase_32 AC 21 ms
8,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
N = int(input())
lscost = [float('INF')]*(N+1)
used = [False]*(N+1)
lscost[1] = 1
d = collections.deque()
d.append(1)
while d:
    v = d.popleft()
    if used[v]:
        continue
    used[v] = True
    bitlen = bin(v).count('1')
    g = [v-bitlen,v+bitlen]
    for j in g:
        if j > N:
            continue
        if lscost[j] > lscost[v]+1:
            lscost[j] = lscost[v]+1
            d.append(j)
if lscost[N] == float('INF'):
    print(-1)
else:
    print(lscost[N])
0