結果
問題 | No.2405 Minimal Matrix Decomposition |
ユーザー | gr1msl3y |
提出日時 | 2023-08-17 17:55:18 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 803 ms / 2,000 ms |
コード長 | 1,722 bytes |
コンパイル時間 | 316 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 79,488 KB |
最終ジャッジ日時 | 2024-05-05 00:37:42 |
合計ジャッジ時間 | 9,918 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
52,224 KB |
testcase_01 | AC | 37 ms
52,224 KB |
testcase_02 | AC | 37 ms
52,480 KB |
testcase_03 | AC | 38 ms
52,352 KB |
testcase_04 | AC | 80 ms
77,184 KB |
testcase_05 | AC | 803 ms
79,488 KB |
testcase_06 | AC | 37 ms
52,224 KB |
testcase_07 | AC | 36 ms
52,480 KB |
testcase_08 | AC | 39 ms
52,352 KB |
testcase_09 | AC | 38 ms
52,224 KB |
testcase_10 | AC | 271 ms
78,464 KB |
testcase_11 | AC | 329 ms
79,488 KB |
testcase_12 | AC | 64 ms
68,608 KB |
testcase_13 | AC | 105 ms
77,312 KB |
testcase_14 | AC | 129 ms
77,184 KB |
testcase_15 | AC | 96 ms
77,184 KB |
testcase_16 | AC | 65 ms
72,960 KB |
testcase_17 | AC | 168 ms
77,696 KB |
testcase_18 | AC | 144 ms
77,312 KB |
testcase_19 | AC | 138 ms
77,568 KB |
testcase_20 | AC | 60 ms
67,328 KB |
testcase_21 | AC | 82 ms
74,880 KB |
testcase_22 | AC | 252 ms
78,976 KB |
testcase_23 | AC | 62 ms
66,688 KB |
testcase_24 | AC | 60 ms
66,944 KB |
testcase_25 | AC | 78 ms
73,728 KB |
testcase_26 | AC | 216 ms
77,696 KB |
testcase_27 | AC | 115 ms
77,568 KB |
testcase_28 | AC | 228 ms
77,696 KB |
testcase_29 | AC | 99 ms
77,312 KB |
testcase_30 | AC | 250 ms
78,336 KB |
testcase_31 | AC | 128 ms
77,184 KB |
testcase_32 | AC | 69 ms
70,144 KB |
testcase_33 | AC | 197 ms
78,080 KB |
testcase_34 | AC | 92 ms
77,184 KB |
testcase_35 | AC | 44 ms
59,520 KB |
testcase_36 | AC | 105 ms
77,568 KB |
testcase_37 | AC | 135 ms
77,824 KB |
testcase_38 | AC | 168 ms
77,568 KB |
testcase_39 | AC | 257 ms
77,696 KB |
testcase_40 | AC | 112 ms
77,440 KB |
testcase_41 | AC | 67 ms
69,760 KB |
testcase_42 | AC | 230 ms
78,720 KB |
testcase_43 | AC | 100 ms
77,184 KB |
testcase_44 | AC | 109 ms
77,056 KB |
testcase_45 | AC | 80 ms
72,448 KB |
testcase_46 | AC | 105 ms
76,928 KB |
testcase_47 | AC | 118 ms
77,184 KB |
testcase_48 | AC | 80 ms
73,600 KB |
testcase_49 | AC | 60 ms
67,456 KB |
ソースコード
def prod(A, B, MOD): n = len(A) m = len(B[0]) res = [[0]*m for _ in range(n)] for i in range(n): for j in range(m): for k in range(len(B)): res[i][j] += A[i][k]*B[k][j] % MOD res[i][j] %= MOD return res P = int(input()) N, M = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(N)] if A == [[0]*M for _ in range(N)]: if min(N, M) == 1: print(1) print(N, M) for _ in range(N): print(*[0]*M) else: print(2) print(N, 1) for _ in range(N): print(0) print(1, M) print(*[0]*M) exit() B = [a[:] for a in A] rank = 0 for r in range(N): for p in range(M): flag = 0 for i in range(r, N): if B[i][p] != 0: flag = 1 break if flag: break else: break rank += 1 B[r], B[i] = B[i], B[r] inv = pow(B[r][p], P-2, P) for j in range(M): B[r][j] = B[r][j]*inv % P for i in range(N): if i == r: continue v = B[i][p] for j in range(M): B[i][j] -= v*B[r][j] % P B[i][j] %= P rank = min(rank, M) if rank*(N+M) >= N*M: print(1) print(N, M) for a in A: print(*a) exit() plist = [] p = 0 for i in range(N): while p < M: if B[i][p] == 1: break p += 1 else: break plist.append(p) p += 1 res0 = [[a[ind] for ind in plist] for a in A] res1 = B[:rank] print(2) print(N, rank) for res in res0: print(*res) print(rank, M) for res in res1: print(*res) # print(prod(res0,res1,P) == A)