結果
問題 | No.2405 Minimal Matrix Decomposition |
ユーザー | gr1msl3y |
提出日時 | 2023-08-17 17:55:18 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 879 ms / 2,000 ms |
コード長 | 1,722 bytes |
コンパイル時間 | 150 ms |
コンパイル使用メモリ | 82,656 KB |
実行使用メモリ | 79,540 KB |
最終ジャッジ日時 | 2024-11-26 16:31:05 |
合計ジャッジ時間 | 10,593 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
52,812 KB |
testcase_01 | AC | 39 ms
54,268 KB |
testcase_02 | AC | 38 ms
53,784 KB |
testcase_03 | AC | 38 ms
54,392 KB |
testcase_04 | AC | 87 ms
77,140 KB |
testcase_05 | AC | 879 ms
79,540 KB |
testcase_06 | AC | 38 ms
53,432 KB |
testcase_07 | AC | 40 ms
53,488 KB |
testcase_08 | AC | 38 ms
53,280 KB |
testcase_09 | AC | 38 ms
52,748 KB |
testcase_10 | AC | 292 ms
78,248 KB |
testcase_11 | AC | 352 ms
79,336 KB |
testcase_12 | AC | 63 ms
69,008 KB |
testcase_13 | AC | 108 ms
77,048 KB |
testcase_14 | AC | 132 ms
77,440 KB |
testcase_15 | AC | 93 ms
77,132 KB |
testcase_16 | AC | 71 ms
73,728 KB |
testcase_17 | AC | 172 ms
77,832 KB |
testcase_18 | AC | 151 ms
77,328 KB |
testcase_19 | AC | 148 ms
77,360 KB |
testcase_20 | AC | 60 ms
69,652 KB |
testcase_21 | AC | 77 ms
74,580 KB |
testcase_22 | AC | 275 ms
78,688 KB |
testcase_23 | AC | 61 ms
67,356 KB |
testcase_24 | AC | 59 ms
67,096 KB |
testcase_25 | AC | 74 ms
73,792 KB |
testcase_26 | AC | 229 ms
78,316 KB |
testcase_27 | AC | 107 ms
77,376 KB |
testcase_28 | AC | 244 ms
77,696 KB |
testcase_29 | AC | 101 ms
77,108 KB |
testcase_30 | AC | 256 ms
78,276 KB |
testcase_31 | AC | 127 ms
76,948 KB |
testcase_32 | AC | 65 ms
70,852 KB |
testcase_33 | AC | 204 ms
78,196 KB |
testcase_34 | AC | 86 ms
76,776 KB |
testcase_35 | AC | 44 ms
60,512 KB |
testcase_36 | AC | 101 ms
77,216 KB |
testcase_37 | AC | 135 ms
77,712 KB |
testcase_38 | AC | 168 ms
77,700 KB |
testcase_39 | AC | 269 ms
77,728 KB |
testcase_40 | AC | 114 ms
77,552 KB |
testcase_41 | AC | 65 ms
69,988 KB |
testcase_42 | AC | 246 ms
78,424 KB |
testcase_43 | AC | 99 ms
76,932 KB |
testcase_44 | AC | 105 ms
77,076 KB |
testcase_45 | AC | 74 ms
73,416 KB |
testcase_46 | AC | 108 ms
76,956 KB |
testcase_47 | AC | 116 ms
76,968 KB |
testcase_48 | AC | 75 ms
74,244 KB |
testcase_49 | AC | 60 ms
68,236 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)