結果
問題 | No.2405 Minimal Matrix Decomposition |
ユーザー | SSRS |
提出日時 | 2023-08-04 22:11:11 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,839 ms / 2,000 ms |
コード長 | 3,971 bytes |
コンパイル時間 | 2,186 ms |
コンパイル使用メモリ | 178,472 KB |
実行使用メモリ | 8,520 KB |
最終ジャッジ日時 | 2024-10-14 20:08:42 |
合計ジャッジ時間 | 15,725 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 54 ms
8,516 KB |
testcase_05 | AC | 1,839 ms
8,520 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 639 ms
6,500 KB |
testcase_11 | AC | 872 ms
7,508 KB |
testcase_12 | AC | 11 ms
5,248 KB |
testcase_13 | AC | 134 ms
5,248 KB |
testcase_14 | AC | 162 ms
5,248 KB |
testcase_15 | AC | 82 ms
5,248 KB |
testcase_16 | AC | 39 ms
5,248 KB |
testcase_17 | AC | 283 ms
5,280 KB |
testcase_18 | AC | 267 ms
5,248 KB |
testcase_19 | AC | 309 ms
5,504 KB |
testcase_20 | AC | 11 ms
5,248 KB |
testcase_21 | AC | 39 ms
5,248 KB |
testcase_22 | AC | 621 ms
6,660 KB |
testcase_23 | AC | 4 ms
5,248 KB |
testcase_24 | AC | 8 ms
5,248 KB |
testcase_25 | AC | 38 ms
5,248 KB |
testcase_26 | AC | 451 ms
5,812 KB |
testcase_27 | AC | 99 ms
5,248 KB |
testcase_28 | AC | 536 ms
6,000 KB |
testcase_29 | AC | 167 ms
5,248 KB |
testcase_30 | AC | 536 ms
6,292 KB |
testcase_31 | AC | 158 ms
5,248 KB |
testcase_32 | AC | 27 ms
5,248 KB |
testcase_33 | AC | 383 ms
5,844 KB |
testcase_34 | AC | 51 ms
5,248 KB |
testcase_35 | AC | 3 ms
5,248 KB |
testcase_36 | AC | 126 ms
5,248 KB |
testcase_37 | AC | 194 ms
5,248 KB |
testcase_38 | AC | 357 ms
5,468 KB |
testcase_39 | AC | 575 ms
5,916 KB |
testcase_40 | AC | 189 ms
5,468 KB |
testcase_41 | AC | 14 ms
5,248 KB |
testcase_42 | AC | 519 ms
6,228 KB |
testcase_43 | AC | 99 ms
5,248 KB |
testcase_44 | AC | 91 ms
5,248 KB |
testcase_45 | AC | 30 ms
5,248 KB |
testcase_46 | AC | 103 ms
5,248 KB |
testcase_47 | AC | 117 ms
5,248 KB |
testcase_48 | AC | 31 ms
5,248 KB |
testcase_49 | AC | 11 ms
5,248 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ int MOD; cin >> MOD; int N, M; cin >> N >> M; auto modpow = [&](long long a, long long b){ long long ans = 1; while (b > 0){ if (b % 2 == 1){ ans *= a; ans %= MOD; } a *= a; a %= MOD; b /= 2; } return ans; }; auto modinv = [&](long long a){ return modpow(a, MOD - 2); }; vector<vector<long long>> A(N, vector<long long>(M)); for (int i = 0; i < N; i++){ for (int j = 0; j < M; j++){ cin >> A[i][j]; } } if (A == vector<vector<long long>>(N, vector<long long>(M, 0))){ if (N + M < N * M){ cout << 2 << endl; cout << N << ' ' << 1 << endl; for (int i = 0; i < N; i++){ cout << 0 << endl; } cout << 1 << ' ' << M << endl; for (int i = 0; i < M; i++){ cout << 0; if (i < M - 1){ cout << ' '; } } cout << endl; } else { cout << 1 << endl; cout << N << ' ' << M << endl; for (int i = 0; i < N; i++){ for (int j = 0; j < M; j++){ cout << 0; if (j < M - 1){ cout << ' '; } } cout << endl; } } } else { vector<vector<long long>> A2 = A; vector<vector<long long>> P(N, vector<long long>(N, 0)); for (int i = 0; i < N; i++){ P[i][i] = 1; } vector<vector<long long>> Q(M, vector<long long>(M, 0)); for (int i = 0; i < M; i++){ Q[i][i] = 1; } int rank = 0; for (int i = 0; i < N; i++){ int x = -1, y = -1; for (int j = i; j < N; j++){ for (int k = i; k < M; k++){ if (A[j][k] != 0){ x = j; y = k; } } } if (x == -1 && y == -1){ break; } rank++; if (x != i){ for (int j = 0; j < N; j++){ swap(P[j][x], P[j][i]); } for (int j = 0; j < M; j++){ swap(A[x][j], A[i][j]); } } if (y != i){ for (int j = 0; j < M; j++){ swap(Q[y][j], Q[i][j]); } for (int j = 0; j < N; j++){ swap(A[j][i], A[j][y]); } } long long m = modinv(A[i][i]); for (int j = 0; j < N; j++){ P[j][i] *= A[i][i]; P[j][i] %= MOD; } for (int j = 0; j < M; j++){ A[i][j] *= m; A[i][j] %= MOD; } for (int j = i + 1; j < N; j++){ long long m2 = A[j][i]; for (int k = 0; k < N; k++){ P[k][i] += P[k][j] * m2; P[k][i] %= MOD; } for (int k = 0; k < M; k++){ A[j][k] -= A[i][k] * m2 % MOD; if (A[j][k] < 0){ A[j][k] += MOD; } } } for (int j = i + 1; j < M; j++){ long long m2 = A[i][j]; for (int k = 0; k < M; k++){ Q[i][k] += Q[j][k] * m2; Q[i][k] %= MOD; } for (int k = 0; k < N; k++){ A[k][j] -= A[k][i] * m2 % MOD; if (A[k][j] < 0){ A[k][j] += MOD; } } } } if (rank * (N + M) < N * M){ cout << 2 << endl; cout << N << ' ' << rank << endl; for (int i = 0; i < N; i++){ for (int j = 0; j < rank; j++){ cout << P[i][j]; if (j < rank - 1){ cout << ' '; } } cout << endl; } cout << rank << ' ' << M << endl; for (int i = 0; i < rank; i++){ for (int j = 0; j < M; j++){ cout << Q[i][j]; if (j < M - 1){ cout << ' '; } } cout << endl; } } else { cout << 1 << endl; cout << N << ' ' << M << endl; for (int i = 0; i < N; i++){ for (int j = 0; j < M; j++){ cout << A2[i][j]; if (j < M - 1){ cout << ' '; } } cout << endl; } } } }