結果

問題 No.3 ビットすごろく
ユーザー shokayamorishokayamori
提出日時 2020-11-28 00:31:48
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 162 ms / 5,000 ms
コード長 621 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 10,976 KB
実行使用メモリ 31,664 KB
最終ジャッジ日時 2023-09-14 01:55:08
合計ジャッジ時間 7,630 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
29,660 KB
testcase_01 AC 144 ms
29,484 KB
testcase_02 AC 140 ms
29,676 KB
testcase_03 AC 143 ms
30,136 KB
testcase_04 AC 141 ms
29,772 KB
testcase_05 AC 149 ms
30,608 KB
testcase_06 AC 145 ms
30,028 KB
testcase_07 AC 142 ms
29,872 KB
testcase_08 AC 148 ms
30,412 KB
testcase_09 AC 152 ms
30,940 KB
testcase_10 AC 159 ms
31,048 KB
testcase_11 AC 158 ms
30,804 KB
testcase_12 AC 152 ms
30,404 KB
testcase_13 AC 141 ms
29,972 KB
testcase_14 AC 155 ms
31,028 KB
testcase_15 AC 161 ms
31,664 KB
testcase_16 AC 162 ms
31,356 KB
testcase_17 AC 158 ms
30,956 KB
testcase_18 AC 143 ms
29,916 KB
testcase_19 AC 162 ms
31,492 KB
testcase_20 AC 141 ms
29,748 KB
testcase_21 AC 140 ms
29,596 KB
testcase_22 AC 160 ms
31,008 KB
testcase_23 AC 160 ms
31,360 KB
testcase_24 AC 157 ms
31,488 KB
testcase_25 AC 158 ms
31,352 KB
testcase_26 AC 137 ms
29,556 KB
testcase_27 AC 141 ms
30,028 KB
testcase_28 AC 157 ms
31,356 KB
testcase_29 AC 152 ms
30,824 KB
testcase_30 AC 138 ms
29,644 KB
testcase_31 AC 139 ms
29,636 KB
testcase_32 AC 153 ms
30,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

N = int(input())

lengths = [bin(i).count('1') for i in range(1, N+1)]

g = []
for i, length in enumerate(lengths):
    backward = i - length
    forward = i + length
    edges = []
    if not backward < 0:
        edges.append(backward)
    if not forward > N-1:
        edges.append(forward)
    g.append(edges)

distances = np.full_like(lengths, -1)
que = []

distances[0] = 1
que.append(0)

while que!=[]:
    v = que.pop(0)
    for next_v in g[v]:
        if distances[next_v]!=-1:
            continue
        distances[next_v] = distances[v] + 1
        que.append(next_v)
print(distances[N-1])
0