結果

問題 No.2445 奇行列式
ユーザー eve__fuyukieve__fuyuki
提出日時 2024-04-11 00:02:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 964 ms / 3,000 ms
コード長 1,138 bytes
コンパイル時間 2,066 ms
コンパイル使用メモリ 199,984 KB
実行使用メモリ 60,640 KB
最終ジャッジ日時 2024-04-11 00:03:02
合計ジャッジ時間 9,137 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 21 ms
6,944 KB
testcase_12 AC 92 ms
10,368 KB
testcase_13 AC 480 ms
31,792 KB
testcase_14 AC 878 ms
60,612 KB
testcase_15 AC 961 ms
60,532 KB
testcase_16 AC 876 ms
60,640 KB
testcase_17 AC 964 ms
60,552 KB
testcase_18 AC 944 ms
60,564 KB
testcase_19 AC 862 ms
60,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main() {
    fast_io();
    int n;
    long long b;
    cin >> n >> b;
    vector<vector<long long>> a(n, vector<long long>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
            a[i][j] %= b;
        }
    }
    vector<vector<long long>> dp(1 << n, vector<long long>(2));
    dp[0][0] = 1;
    for (int st = 0; st < (1 << n); st++) {
        int p = __builtin_popcount(st);
        for (int i = 0; i < n; i++) {
            if ((st >> i) & 1) {
                continue;
            }
            int is_odd = 0;
            for (int j = 0; j < i; j++) {
                if (((st >> j) & 1) == 0) {
                    is_odd ^= 1;
                }
            }
            dp[st | (1 << i)][is_odd] += dp[st][0] * a[i][p] % b;
            dp[st | (1 << i)][is_odd] %= b;
            dp[st | (1 << i)][is_odd ^ 1] += dp[st][1] * a[i][p] % b;
            dp[st | (1 << i)][is_odd ^ 1] %= b;
        }
    }
    cout << dp.back()[1] << "\n";
}
0