結果

問題 No.2445 奇行列式
ユーザー titiatitia
提出日時 2023-08-31 02:59:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,340 ms / 3,000 ms
コード長 734 bytes
コンパイル時間 787 ms
コンパイル使用メモリ 87,296 KB
実行使用メモリ 93,932 KB
最終ジャッジ日時 2023-08-31 02:59:21
合計ジャッジ時間 17,300 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,508 KB
testcase_01 AC 70 ms
71,456 KB
testcase_02 AC 70 ms
71,480 KB
testcase_03 AC 71 ms
71,276 KB
testcase_04 AC 71 ms
71,560 KB
testcase_05 AC 72 ms
71,280 KB
testcase_06 AC 71 ms
71,356 KB
testcase_07 AC 80 ms
76,724 KB
testcase_08 AC 89 ms
76,656 KB
testcase_09 AC 74 ms
71,280 KB
testcase_10 AC 77 ms
71,484 KB
testcase_11 AC 146 ms
77,708 KB
testcase_12 AC 322 ms
79,136 KB
testcase_13 AC 1,156 ms
85,588 KB
testcase_14 AC 2,340 ms
93,872 KB
testcase_15 AC 2,330 ms
93,680 KB
testcase_16 AC 2,326 ms
93,768 KB
testcase_17 AC 2,305 ms
93,932 KB
testcase_18 AC 2,318 ms
93,792 KB
testcase_19 AC 712 ms
93,588 KB
権限があれば一括ダウンロードができます

ソースコード

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|(1<<j)]+DP0[i]*A[c][j]%B)%B
                DP1[i|(1<<j)]=(DP1[i|(1<<j)]+DP1[i]*A[c][j]%B)%B
            else:
                DP0[i|(1<<j)]=(DP0[i|(1<<j)]+DP1[i]*A[c][j]%B)%B
                DP1[i|(1<<j)]=(DP1[i|(1<<j)]+DP0[i]*A[c][j]%B)%B
        
print(DP1[-1]%B)
0