結果

問題 No.2445 奇行列式
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-08-25 22:53:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 781 ms / 3,000 ms
コード長 990 bytes
コンパイル時間 1,985 ms
コンパイル使用メモリ 203,768 KB
実行使用メモリ 60,452 KB
最終ジャッジ日時 2023-08-25 22:53:33
合計ジャッジ時間 8,082 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 20 ms
4,876 KB
testcase_12 AC 83 ms
10,176 KB
testcase_13 AC 360 ms
31,788 KB
testcase_14 AC 753 ms
60,360 KB
testcase_15 AC 759 ms
60,352 KB
testcase_16 AC 781 ms
60,452 KB
testcase_17 AC 754 ms
60,420 KB
testcase_18 AC 758 ms
60,432 KB
testcase_19 AC 767 ms
60,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){
    
    ll N, B, M, x, c, d;
    cin >> N >> B;
    vector<vector<ll>> A(N, vector<ll>(N));
    for (int i=0; i<N; i++){
        for (int j=0; j<N; j++){
            cin >> A[i][j];
            A[i][j] %= B;
        }
    }

    M = 1<<N;
    vector<vector<ll>> dp(M, vector<ll>(2));
    dp[0][0] = 1;

    for (int i=0; i<N; i++){
        x = M-1 - ((1<<i)-1);
    }

    
    for (int i=0; i<M; i++){
        for (int j=0; j<N; j++){
            if (i & 1<<j) continue;
            x = M-1 - ((1<<j)-1);
            c = __builtin_popcount(x & i); //(x以上のものでiに含まれるものの数)
            d = __builtin_popcount(i); //(iに含まれるものの要素数)
            for (int k=0; k<2; k++){
                dp[i|(1<<j)][(k+c)%2] += (dp[i][k] * A[d][j]) % B;
                dp[i|(1<<j)][(k+c)%2] %= B;
            }
        }
    }

    cout << dp[M-1][1] << endl;

    return 0;
}
0