結果

問題 No.2445 奇行列式
ユーザー titiatitia
提出日時 2023-08-31 02:56:45
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 718 bytes
コンパイル時間 978 ms
コンパイル使用メモリ 87,260 KB
実行使用メモリ 163,676 KB
最終ジャッジ日時 2023-08-31 02:56:58
合計ジャッジ時間 12,273 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,476 KB
testcase_01 AC 72 ms
71,300 KB
testcase_02 AC 71 ms
71,616 KB
testcase_03 AC 69 ms
71,436 KB
testcase_04 AC 68 ms
71,372 KB
testcase_05 AC 71 ms
71,368 KB
testcase_06 AC 75 ms
71,324 KB
testcase_07 AC 80 ms
76,640 KB
testcase_08 AC 86 ms
76,668 KB
testcase_09 AC 67 ms
71,388 KB
testcase_10 AC 71 ms
71,396 KB
testcase_11 AC 191 ms
80,492 KB
testcase_12 AC 584 ms
94,696 KB
testcase_13 AC 2,445 ms
163,676 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# 転倒数を持つDP

import sys
input = sys.stdin.readline

N,B=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N)]

DP0=[0]*(1<<N)
DP1=[0]*(1<<N)

DP0[0]=1

for i in range(1<<N):
    c=0
    for j in range(N):
        if i & (1<<j) !=0:
            c+=1
            
    count=0
    for j in range(N-1,-1,-1):
        if i & (1<<j) != 0:
            count+=1

        else:
            if count%2==0:
                DP0[i|(1<<j)]+=DP0[i]*A[c][j]
                DP1[i|(1<<j)]+=DP1[i]*A[c][j]
            else:
                DP0[i|(1<<j)]+=DP1[i]*A[c][j]
                DP1[i|(1<<j)]+=DP0[i]*A[c][j]

            DP0[i|(1<<j)]%=B
            DP1[i|(1<<j)]%=B

        
print(DP1[-1]%B)
0