結果

問題 No.2263 Perms
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2023-04-07 22:19:03
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 996 bytes
コンパイル時間 344 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 79,968 KB
最終ジャッジ日時 2024-04-10 17:19:59
合計ジャッジ時間 7,561 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
56,260 KB
testcase_01 AC 39 ms
55,148 KB
testcase_02 AC 36 ms
55,036 KB
testcase_03 AC 39 ms
55,772 KB
testcase_04 AC 38 ms
55,824 KB
testcase_05 AC 67 ms
71,696 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 236 ms
78,124 KB
testcase_09 RE -
testcase_10 AC 39 ms
62,072 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 39 ms
61,844 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 AC 36 ms
55,196 KB
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 AC 38 ms
55,088 KB
testcase_40 AC 35 ms
54,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import random

n,m = map(int,input().split())
A = [list(map(int,input().split())) for i in range(n)]

for i in range(n):
    r = 0
    c = 0
    for j in range(n):
        r += A[i][j]
        c += A[j][i]
    if r != m or c != m:
        print(-1)
        exit()


ans = []
for _ in range(m):
    l = [0]*n

    H = [0]*n
    W = [0]*n
    for i in range(n):
        ma = m
        for h in range(n):
            for w in range(n):
                if H[h] or W[w] or A[h][w] == 0:
                    continue
                ma = min(ma,A[h][w])
        
        cands = []
        
        for h in range(n):
            for w in range(n):
                if H[h] or W[w]:
                    continue
                if A[h][w] == ma:
                    cands.append([h,w])

        # assert cands
        rind = random.randint(0,len(cands)-1)
        h,w = cands[rind]
        A[h][w] -= 1
        H[h] = 1
        W[w] = 1
        l[h] = w+1
    ans.append(l)


for i in ans:
    print(*i)
0