結果
問題 | No.2255 Determinant Sum |
ユーザー | kuroni |
提出日時 | 2023-04-06 12:16:31 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,992 bytes |
コンパイル時間 | 3,512 ms |
コンパイル使用メモリ | 288,440 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-04-10 10:04:32 |
合計ジャッジ時間 | 6,414 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 37 ms
6,940 KB |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | AC | 27 ms
6,940 KB |
testcase_11 | AC | 9 ms
6,944 KB |
testcase_12 | RE | - |
testcase_13 | AC | 9 ms
6,940 KB |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | AC | 9 ms
6,940 KB |
testcase_19 | AC | 10 ms
6,944 KB |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | AC | 10 ms
6,944 KB |
ソースコード
#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'; } } }