結果

問題 No.2445 奇行列式
ユーザー 👑 KazunKazun
提出日時 2023-08-25 22:49:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,046 ms / 3,000 ms
コード長 959 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 87,016 KB
実行使用メモリ 101,948 KB
最終ジャッジ日時 2023-08-25 22:49:26
合計ジャッジ時間 9,187 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,264 KB
testcase_01 AC 72 ms
71,676 KB
testcase_02 AC 73 ms
71,348 KB
testcase_03 AC 73 ms
71,456 KB
testcase_04 AC 73 ms
71,292 KB
testcase_05 AC 75 ms
71,556 KB
testcase_06 AC 73 ms
71,160 KB
testcase_07 AC 82 ms
76,724 KB
testcase_08 AC 85 ms
76,808 KB
testcase_09 AC 72 ms
71,508 KB
testcase_10 AC 73 ms
71,188 KB
testcase_11 AC 108 ms
77,488 KB
testcase_12 AC 171 ms
80,408 KB
testcase_13 AC 463 ms
89,484 KB
testcase_14 AC 1,044 ms
101,700 KB
testcase_15 AC 1,039 ms
101,804 KB
testcase_16 AC 1,013 ms
101,940 KB
testcase_17 AC 1,036 ms
101,948 KB
testcase_18 AC 1,046 ms
101,848 KB
testcase_19 AC 1,025 ms
101,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
    N, B = map(int, input().split())

    A = [None] * N
    for i in range(N):
        A[i] = list(map(int, input().split()))
        A[i] = [a % B for a in A[i]]

    popcount = [0] * (1 << N)
    for S in range(1, 1 << N):
        x = S & (-S)
        popcount[S] = popcount[S ^ x] + 1

    bit = lambda S,k : (S>>k) & 1
    DP0 = [0] * (1 << N); DP0[0] = 1
    DP1 = [0] * (1 << N)

    for S in range(1 << N):
        t = 0
        i = popcount[S]
        for k in range(N):
            if not bit(S, k):
                T = S | (1 << k)
                if t % 2 == 0:
                    DP0[T] += DP0[S] * A[i][k]; DP0[T] %= B
                    DP1[T] += DP1[S] * A[i][k]; DP1[T] %= B
                else:
                    DP0[T] += DP1[S] * A[i][k]; DP0[T] %= B
                    DP1[T] += DP0[S] * A[i][k]; DP1[T] %= B
                t += 1
    return DP1[-1]

#==================================================
print(solve())
0