結果

問題 No.3 ビットすごろく
ユーザー nktankta
提出日時 2022-06-15 09:37:09
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 249 ms / 5,000 ms
コード長 815 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 10,988 KB
実行使用メモリ 30,072 KB
最終ジャッジ日時 2023-07-27 04:30:10
合計ジャッジ時間 10,621 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
29,736 KB
testcase_01 AC 144 ms
29,752 KB
testcase_02 AC 141 ms
29,848 KB
testcase_03 AC 164 ms
29,888 KB
testcase_04 AC 149 ms
29,824 KB
testcase_05 AC 190 ms
29,924 KB
testcase_06 AC 164 ms
29,804 KB
testcase_07 AC 153 ms
29,884 KB
testcase_08 AC 179 ms
29,896 KB
testcase_09 AC 207 ms
29,896 KB
testcase_10 AC 221 ms
30,000 KB
testcase_11 AC 201 ms
29,920 KB
testcase_12 AC 189 ms
29,880 KB
testcase_13 AC 162 ms
29,768 KB
testcase_14 AC 220 ms
29,932 KB
testcase_15 AC 246 ms
29,912 KB
testcase_16 AC 236 ms
29,984 KB
testcase_17 AC 247 ms
30,052 KB
testcase_18 AC 159 ms
29,824 KB
testcase_19 AC 246 ms
30,008 KB
testcase_20 AC 147 ms
29,816 KB
testcase_21 AC 141 ms
29,852 KB
testcase_22 AC 229 ms
29,976 KB
testcase_23 AC 245 ms
29,944 KB
testcase_24 AC 243 ms
30,072 KB
testcase_25 AC 249 ms
29,936 KB
testcase_26 AC 142 ms
29,852 KB
testcase_27 AC 167 ms
29,832 KB
testcase_28 AC 230 ms
29,940 KB
testcase_29 AC 201 ms
29,816 KB
testcase_30 AC 138 ms
29,884 KB
testcase_31 AC 140 ms
29,872 KB
testcase_32 AC 198 ms
29,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

N = int(input())

def get_bit_sum(num):
    return bin(num).count("1")

visited = np.zeros((N,)).astype(bool)
min_value = np.zeros((N,)) + 1e10
pre_visited = visited.copy()
visited[0] = 1
min_value[0] = 1

while np.sum(visited^pre_visited)>0:
    arg = np.argwhere(pre_visited^visited).reshape(-1)
    move = np.array([get_bit_sum(i) for i in arg+1])
    move = np.concatenate([move,-move])
    arg = np.concatenate([arg,arg])
    min_values = min_value[arg]+1
    for i in range(arg.shape[0]):
        position = arg[i]+move[i]
        if position<1 or position>N-1:
            continue
        min_value[position] = min(min_values[i],min_value[position])
    pre_visited = visited.copy()
    visited = min_value < 1e10
output = min_value[-1] if min_value[-1]<1e10 else -1
print(int(output))

0