結果

問題 No.2263 Perms
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2023-04-07 22:15:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 980 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 82,544 KB
実行使用メモリ 79,536 KB
最終ジャッジ日時 2024-04-10 17:17:43
合計ジャッジ時間 10,071 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
56,088 KB
testcase_01 AC 38 ms
55,276 KB
testcase_02 AC 40 ms
55,168 KB
testcase_03 AC 39 ms
55,388 KB
testcase_04 AC 40 ms
54,596 KB
testcase_05 AC 65 ms
73,268 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 246 ms
77,968 KB
testcase_09 WA -
testcase_10 AC 42 ms
60,920 KB
testcase_11 RE -
testcase_12 WA -
testcase_13 WA -
testcase_14 RE -
testcase_15 AC 43 ms
61,864 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 RE -
testcase_21 WA -
testcase_22 RE -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 55 ms
68,584 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 40 ms
55,988 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 42 ms
54,572 KB
testcase_40 AC 42 ms
54,344 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 = 0
        for h in range(n):
            for w in range(n):
                if H[h] or W[w]:
                    continue
                ma = max(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