結果

問題 No.1937 Various Tournament
ユーザー 👑 rin204rin204
提出日時 2022-05-13 22:10:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 835 ms / 2,000 ms
コード長 1,310 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 86,708 KB
実行使用メモリ 91,104 KB
最終ジャッジ日時 2023-09-29 07:29:32
合計ジャッジ時間 29,778 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
75,864 KB
testcase_01 AC 799 ms
90,976 KB
testcase_02 AC 807 ms
90,796 KB
testcase_03 AC 808 ms
91,104 KB
testcase_04 AC 810 ms
90,844 KB
testcase_05 AC 100 ms
76,284 KB
testcase_06 AC 816 ms
90,664 KB
testcase_07 AC 822 ms
90,672 KB
testcase_08 AC 96 ms
76,140 KB
testcase_09 AC 824 ms
90,988 KB
testcase_10 AC 97 ms
76,408 KB
testcase_11 AC 811 ms
90,972 KB
testcase_12 AC 817 ms
90,596 KB
testcase_13 AC 830 ms
90,828 KB
testcase_14 AC 815 ms
90,780 KB
testcase_15 AC 822 ms
90,828 KB
testcase_16 AC 811 ms
90,816 KB
testcase_17 AC 809 ms
90,664 KB
testcase_18 AC 820 ms
90,764 KB
testcase_19 AC 835 ms
90,788 KB
testcase_20 AC 97 ms
76,264 KB
testcase_21 AC 83 ms
75,872 KB
testcase_22 AC 815 ms
90,780 KB
testcase_23 AC 799 ms
90,848 KB
testcase_24 AC 816 ms
90,756 KB
testcase_25 AC 100 ms
76,292 KB
testcase_26 AC 810 ms
90,824 KB
testcase_27 AC 84 ms
75,876 KB
testcase_28 AC 803 ms
90,576 KB
testcase_29 AC 100 ms
76,236 KB
testcase_30 AC 823 ms
90,916 KB
testcase_31 AC 818 ms
90,972 KB
testcase_32 AC 814 ms
91,036 KB
testcase_33 AC 816 ms
90,560 KB
testcase_34 AC 815 ms
91,020 KB
testcase_35 AC 834 ms
90,972 KB
testcase_36 AC 807 ms
91,048 KB
testcase_37 AC 98 ms
76,520 KB
testcase_38 AC 96 ms
76,320 KB
testcase_39 AC 813 ms
90,708 KB
testcase_40 AC 96 ms
76,460 KB
testcase_41 AC 98 ms
76,488 KB
testcase_42 AC 812 ms
91,036 KB
testcase_43 AC 97 ms
76,328 KB
testcase_44 AC 83 ms
75,512 KB
testcase_45 AC 831 ms
91,016 KB
testcase_46 AC 99 ms
76,124 KB
testcase_47 AC 80 ms
75,720 KB
testcase_48 AC 82 ms
75,820 KB
testcase_49 AC 96 ms
76,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def popcount(x):
    x = x - ((x >> 1) & 0x55555555)
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f
    x += x >> 8
    x += x >> 16
    return x & 0x0000003f

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

dp = [[0] * n for _ in range(1 << n)]
for i in range(n):
    dp[1 << i][i] = 1

bits = [[] for _ in range(17)]
se2 = {2, 4, 8, 16}
for i in se2:
    for j in range(1 << i):
        if popcount(j) == i >> 1:
            bits[i >> 1].append(j)
x = 0

for bit in range(3, 1 << n):
    cnt = 0
    lst = []
    for i in range(n):
        if bit >> i & 1:
            lst.append(i)
            cnt += 1
    if cnt not in se2:
        continue
    half = cnt >> 1
    x += len(bits[half])
    for bbit in bits[half]:
        b1 = 0
        b2 = 0
        l1 = []
        l2 = []
        for i in range(cnt):
            if bbit >> i & 1:
                b1 |= 1 << lst[i]
                l1.append(lst[i])
            else:
                b2 |= 1 << lst[i]
                l2.append(lst[i])
        for i in l1:
            for j in l2:
                if S[i][j]:
                    dp[bit][i] += dp[b1][i] * dp[b2][j]
                else:
                    dp[bit][j] += dp[b2][j] * dp[b1][i]
                

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