結果
問題 | No.2255 Determinant Sum |
ユーザー |
|
提出日時 | 2023-04-06 12:16:31 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,992 bytes |
コンパイル時間 | 3,197 ms |
コンパイル使用メモリ | 259,564 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-02 11:54:34 |
合計ジャッジ時間 | 6,184 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 9 RE * 14 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/modint>using namespace std;using namespace atcoder;using mint = modint;int main() {ios_base::sync_with_stdio(false);cin.tie(nullptr);int t; cin >> t;while (t--) {int n, p; cin >> n >> p;mint::set_mod(p);vector a(n, vector<mint>(n));vector<int> row(n), col(n);for (int i = 0; i < n; i++) {for (int j = 0; j < n; j++) {int u; cin >> u;row[i] += (u == -1);col[j] += (u == -1);a[i][j] = u;}}int mir = *min_element(row.begin(), row.end()),mxr = *max_element(row.begin(), row.end()),mic = *min_element(col.begin(), col.end()),mxc = *max_element(col.begin(), col.end());if (mxr > 1 || mxc > 1) {cout << "0\n";} else {for (int i = n - 1; i >= 0; i--) {if (col[i]) {for (int j = 0; j < n; j++) {a[j].erase(a[j].begin() + i);}}}for (int i = n - 1; i >= 0; i--) {if (row[i]) {a.erase(a.begin() + i);}}mint ans = (p == 2);n = a.size();for (int i = 0; i < n; i++) {for (int j = i; j < n; j++) {if (a[j][i] != 0) {swap(a[i], a[j]);break;}}if ((ans *= a[i][i]) == 0) {break;}for (int j = i + 1; j < n; j++) {mint d = a[j][i] / a[i][i];for (int k = i; k < n; i++) {a[j][k] -= a[i][k] * d;}}}cout << ans.val() << '\n';}}}