結果

問題 No.241 出席番号(1)
ユーザー H3PO4H3PO4
提出日時 2020-06-04 22:12:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 208 ms / 2,000 ms
コード長 506 bytes
コンパイル時間 206 ms
コンパイル使用メモリ 10,888 KB
実行使用メモリ 80,716 KB
最終ジャッジ日時 2023-08-20 07:28:43
合計ジャッジ時間 11,625 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 203 ms
42,756 KB
testcase_01 AC 198 ms
42,828 KB
testcase_02 AC 199 ms
42,776 KB
testcase_03 AC 206 ms
42,732 KB
testcase_04 AC 200 ms
42,884 KB
testcase_05 AC 200 ms
42,700 KB
testcase_06 AC 208 ms
42,900 KB
testcase_07 AC 203 ms
42,840 KB
testcase_08 AC 207 ms
42,820 KB
testcase_09 AC 203 ms
42,812 KB
testcase_10 AC 199 ms
42,740 KB
testcase_11 AC 200 ms
42,332 KB
testcase_12 AC 200 ms
42,836 KB
testcase_13 AC 200 ms
42,672 KB
testcase_14 AC 200 ms
43,012 KB
testcase_15 AC 203 ms
42,884 KB
testcase_16 AC 201 ms
42,332 KB
testcase_17 AC 202 ms
42,772 KB
testcase_18 AC 203 ms
42,772 KB
testcase_19 AC 203 ms
43,028 KB
testcase_20 AC 201 ms
42,876 KB
testcase_21 AC 198 ms
42,832 KB
testcase_22 AC 196 ms
42,740 KB
testcase_23 AC 206 ms
42,840 KB
testcase_24 AC 205 ms
42,956 KB
testcase_25 AC 205 ms
43,188 KB
testcase_26 AC 207 ms
42,828 KB
testcase_27 AC 205 ms
42,360 KB
testcase_28 AC 206 ms
42,972 KB
testcase_29 AC 205 ms
42,888 KB
testcase_30 AC 200 ms
43,000 KB
testcase_31 AC 203 ms
80,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import maximum_bipartite_matching

N = int(input())
A = [int(input()) for _ in range(N)]

st = set(A)
if len(st) == 1 and st.pop() < N:
    print(-1)
    exit()

frm, to = [], []
for i, a in enumerate(A):
    for j in range(N):
        if j == a:
            continue
        frm.append(i)
        to.append(j)

matr = csr_matrix(([1] * len(frm), (frm, to)), shape=(N, N))
print(*maximum_bipartite_matching(matr, perm_type='column'), sep='\n')
0