結果

問題 No.3 ビットすごろく
ユーザー H3PO4H3PO4
提出日時 2020-04-17 09:10:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 226 ms / 5,000 ms
コード長 490 bytes
コンパイル時間 533 ms
コンパイル使用メモリ 10,880 KB
実行使用メモリ 45,000 KB
最終ジャッジ日時 2023-09-14 01:42:07
合計ジャッジ時間 10,420 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 204 ms
42,872 KB
testcase_01 AC 209 ms
42,884 KB
testcase_02 AC 206 ms
43,076 KB
testcase_03 AC 209 ms
43,724 KB
testcase_04 AC 207 ms
43,024 KB
testcase_05 AC 216 ms
43,732 KB
testcase_06 AC 209 ms
43,472 KB
testcase_07 AC 215 ms
43,236 KB
testcase_08 AC 216 ms
43,684 KB
testcase_09 AC 219 ms
44,376 KB
testcase_10 AC 220 ms
44,340 KB
testcase_11 AC 216 ms
43,868 KB
testcase_12 AC 214 ms
43,772 KB
testcase_13 AC 211 ms
43,312 KB
testcase_14 AC 221 ms
44,420 KB
testcase_15 AC 219 ms
44,760 KB
testcase_16 AC 215 ms
44,408 KB
testcase_17 AC 224 ms
44,840 KB
testcase_18 AC 209 ms
43,636 KB
testcase_19 AC 223 ms
44,808 KB
testcase_20 AC 210 ms
42,976 KB
testcase_21 AC 208 ms
42,840 KB
testcase_22 AC 217 ms
44,392 KB
testcase_23 AC 220 ms
44,724 KB
testcase_24 AC 222 ms
45,000 KB
testcase_25 AC 223 ms
44,920 KB
testcase_26 AC 206 ms
42,768 KB
testcase_27 AC 212 ms
43,672 KB
testcase_28 AC 226 ms
44,096 KB
testcase_29 AC 222 ms
43,784 KB
testcase_30 AC 208 ms
43,124 KB
testcase_31 AC 209 ms
43,024 KB
testcase_32 AC 218 ms
43,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix

N = int(input())
Frm, To = [], []
for i in range(1, N + 1):
    b = bin(i).count('1')
    if i - b >= 1:
        Frm.append(i)
        To.append(i - b)
    if i + b <= N:
        Frm.append(i)
        To.append(i + b)

matr = csr_matrix((np.ones_like(Frm, dtype=int), (Frm, To)), shape=(N + 1, N + 1))
way = dijkstra(matr, indices=1).astype(int)
print(ans if (ans := way[N] + 1) > 0 else -1)
0