結果

問題 No.2445 奇行列式
ユーザー tassei903tassei903
提出日時 2023-08-25 22:13:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,282 ms / 3,000 ms
コード長 1,474 bytes
コンパイル時間 1,851 ms
コンパイル使用メモリ 86,864 KB
実行使用メモリ 93,572 KB
最終ジャッジ日時 2023-08-25 22:13:54
合計ジャッジ時間 15,824 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,400 KB
testcase_01 AC 71 ms
71,340 KB
testcase_02 AC 70 ms
70,980 KB
testcase_03 AC 71 ms
71,060 KB
testcase_04 AC 71 ms
71,080 KB
testcase_05 AC 75 ms
71,076 KB
testcase_06 AC 73 ms
71,260 KB
testcase_07 AC 85 ms
76,364 KB
testcase_08 AC 86 ms
76,576 KB
testcase_09 AC 72 ms
71,116 KB
testcase_10 AC 72 ms
71,300 KB
testcase_11 AC 143 ms
77,892 KB
testcase_12 AC 307 ms
79,064 KB
testcase_13 AC 1,150 ms
85,428 KB
testcase_14 AC 2,261 ms
93,372 KB
testcase_15 AC 2,257 ms
93,296 KB
testcase_16 AC 2,270 ms
93,532 KB
testcase_17 AC 2,266 ms
93,248 KB
testcase_18 AC 2,282 ms
93,396 KB
testcase_19 AC 691 ms
93,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################
def popcnt3(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c
n, mod = na()
a = [na() for i in range(n)]
dp0 = [0] * (1<<n)
dp1 = [0] * (1<<n)
dp0[0] = 1
t = [((1 << n) - (1 << j)) for j in range(n)]
for i in range(1<<n):
    pc = popcnt3(i)
    for j in range(n):
        if i >> j & 1:
            continue
        c = popcnt3(i & t[j])
        if c % 2:
            dp0[i | (1<<j)] += dp1[i] * a[pc][j] % mod
            dp0[i | (1<<j)] %= mod
            dp1[i | (1<<j)] += dp0[i] * a[pc][j] % mod
            dp1[i | (1<<j)] %= mod
        else:
            dp0[i | (1<<j)] += dp0[i] * a[pc][j] % mod
            dp0[i | (1<<j)] %= mod
            dp1[i | (1<<j)] += dp1[i] * a[pc][j] % mod
            dp1[i | (1<<j)] %= mod
#print(dp0, dp1)
print(dp1[-1])
0