結果

問題 No.2255 Determinant Sum
ユーザー kuronikuroni
提出日時 2023-04-06 06:55:36
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,677 bytes
コンパイル時間 4,001 ms
コンパイル使用メモリ 285,480 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 06:31:23
合計ジャッジ時間 4,886 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 (mir == 0 && mxr == 0) {
            mint ans = 1;
            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';
        } else if (mir == 1 && mxr == 1 && mic == 1 && mxc == 1 && p == 2) {
            cout << "1\n";
        } else {
            cout << "0\n";
        }
    }
}
0