結果

問題 No.1937 Various Tournament
ユーザー 👑 KazunKazun
提出日時 2022-05-13 22:49:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 797 ms / 2,000 ms
コード長 888 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 86,808 KB
実行使用メモリ 91,884 KB
最終ジャッジ日時 2023-09-29 08:28:07
合計ジャッジ時間 27,612 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
70,940 KB
testcase_01 AC 749 ms
91,740 KB
testcase_02 AC 752 ms
91,516 KB
testcase_03 AC 757 ms
91,500 KB
testcase_04 AC 766 ms
91,564 KB
testcase_05 AC 86 ms
76,000 KB
testcase_06 AC 763 ms
91,388 KB
testcase_07 AC 767 ms
91,492 KB
testcase_08 AC 83 ms
76,076 KB
testcase_09 AC 767 ms
91,376 KB
testcase_10 AC 85 ms
76,064 KB
testcase_11 AC 760 ms
91,572 KB
testcase_12 AC 755 ms
91,440 KB
testcase_13 AC 780 ms
91,500 KB
testcase_14 AC 765 ms
91,524 KB
testcase_15 AC 780 ms
91,240 KB
testcase_16 AC 779 ms
91,756 KB
testcase_17 AC 752 ms
91,884 KB
testcase_18 AC 797 ms
91,600 KB
testcase_19 AC 790 ms
91,488 KB
testcase_20 AC 88 ms
76,076 KB
testcase_21 AC 80 ms
71,260 KB
testcase_22 AC 787 ms
91,292 KB
testcase_23 AC 782 ms
91,396 KB
testcase_24 AC 759 ms
91,672 KB
testcase_25 AC 83 ms
75,940 KB
testcase_26 AC 775 ms
91,368 KB
testcase_27 AC 74 ms
71,084 KB
testcase_28 AC 748 ms
91,656 KB
testcase_29 AC 86 ms
76,176 KB
testcase_30 AC 766 ms
91,300 KB
testcase_31 AC 756 ms
91,568 KB
testcase_32 AC 781 ms
91,508 KB
testcase_33 AC 765 ms
91,360 KB
testcase_34 AC 765 ms
91,524 KB
testcase_35 AC 773 ms
91,292 KB
testcase_36 AC 763 ms
91,504 KB
testcase_37 AC 85 ms
75,836 KB
testcase_38 AC 85 ms
76,408 KB
testcase_39 AC 760 ms
91,584 KB
testcase_40 AC 85 ms
75,840 KB
testcase_41 AC 84 ms
75,884 KB
testcase_42 AC 777 ms
91,360 KB
testcase_43 AC 86 ms
76,004 KB
testcase_44 AC 72 ms
71,224 KB
testcase_45 AC 774 ms
91,516 KB
testcase_46 AC 88 ms
76,132 KB
testcase_47 AC 72 ms
71,076 KB
testcase_48 AC 74 ms
71,272 KB
testcase_49 AC 83 ms
76,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import combinations

N=int(input())

S=[]
for _ in range(N):
    S.append(list(map(int,input().split())))

DP=[[0]*N for _ in range(1<<N)]
for i in range(N):
    DP[1<<i][i]=1

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

E=[A for A in range(1,1<<N) if (popcount[A]==1 or popcount[A]==2 or popcount[A]==4 or popcount[A]==8) and popcount[A]<N]
E.sort(key=lambda A:popcount[A])

for A in E:
    X=[]; Y=[]
    for a in range(N):
        if (A>>a)&1:
            X.append(a)
        else:
            Y.append(a)

    for B in combinations(Y,popcount[A]):
        T=0
        for b in B:
            T|=1<<b

        for a in X:
            for b in B:
                if S[a][b]==1:
                    DP[A|T][a]+=DP[A][a]*DP[T][b]
                else:
                    DP[A|T][b]+=DP[A][a]*DP[T][b]

print(*DP[-1],sep="\n")
0