結果

問題 No.2255 Determinant Sum
ユーザー kuronikuroni
提出日時 2023-04-06 12:21:13
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 2,026 bytes
コンパイル時間 3,795 ms
コンパイル使用メモリ 288,380 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 10:05:22
合計ジャッジ時間 5,115 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 38 ms
6,940 KB
testcase_07 AC 26 ms
6,944 KB
testcase_08 AC 20 ms
6,940 KB
testcase_09 AC 21 ms
6,940 KB
testcase_10 AC 28 ms
6,940 KB
testcase_11 AC 9 ms
6,940 KB
testcase_12 AC 12 ms
6,940 KB
testcase_13 AC 9 ms
6,944 KB
testcase_14 AC 35 ms
6,944 KB
testcase_15 AC 15 ms
6,944 KB
testcase_16 AC 15 ms
6,940 KB
testcase_17 AC 16 ms
6,944 KB
testcase_18 AC 10 ms
6,944 KB
testcase_19 AC 11 ms
6,940 KB
testcase_20 AC 12 ms
6,944 KB
testcase_21 AC 13 ms
6,944 KB
testcase_22 AC 11 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 j = n - 1; j >= 0; j--) {
                if (col[j]) {
                    for (int i = 0; i < n; i++) {
                        a[i].erase(a[i].begin() + j);
                    }
                }
            }
            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; k++) {
                        a[j][k] -= a[i][k] * d;
                    }
                }
            }
            // cerr << n << '\n';
            cout << ans.val() << '\n';
        }
    }
}
0