結果

問題 No.1767 BLUE to RED
ユーザー H3PO4H3PO4
提出日時 2021-11-26 22:54:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,372 ms / 2,000 ms
コード長 635 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 10,700 KB
実行使用メモリ 193,992 KB
最終ジャッジ日時 2023-09-12 05:22:56
合計ジャッジ時間 21,568 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,372 ms
43,372 KB
testcase_01 AC 221 ms
43,184 KB
testcase_02 AC 220 ms
43,244 KB
testcase_03 AC 218 ms
43,164 KB
testcase_04 AC 218 ms
43,368 KB
testcase_05 AC 216 ms
43,404 KB
testcase_06 AC 216 ms
43,324 KB
testcase_07 AC 222 ms
43,596 KB
testcase_08 AC 221 ms
43,680 KB
testcase_09 AC 679 ms
108,240 KB
testcase_10 AC 797 ms
128,724 KB
testcase_11 AC 703 ms
111,312 KB
testcase_12 AC 674 ms
107,972 KB
testcase_13 AC 869 ms
137,052 KB
testcase_14 AC 1,018 ms
159,524 KB
testcase_15 AC 1,009 ms
159,348 KB
testcase_16 AC 1,017 ms
159,592 KB
testcase_17 AC 1,016 ms
159,348 KB
testcase_18 AC 999 ms
159,244 KB
testcase_19 AC 1,016 ms
159,556 KB
testcase_20 AC 1,012 ms
159,432 KB
testcase_21 AC 1,019 ms
159,392 KB
testcase_22 AC 1,018 ms
159,284 KB
testcase_23 AC 1,022 ms
193,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from scipy.sparse.csgraph import minimum_spanning_tree
from scipy.sparse import csr_matrix

N, M = map(int, input().split())
A = map(int, input().split())
B = map(int, input().split())
nodes = []
for i, a in enumerate(A):
    nodes.append((a, i))
for i, b in enumerate(B, N):
    nodes.append((b, i))
nodes.sort()

length = [0] * N
frm = list(range(N))
to = [N + M] * N

for i in range(N + M - 1):
    frm.append(nodes[i][1])
    to.append(nodes[i + 1][1])
    length.append(nodes[i + 1][0] - nodes[i][0])

matr = csr_matrix((length, (frm, to)), shape=(N + M + 1, N + M + 1))
T = minimum_spanning_tree(matr).astype(int)
print(T.sum())
0