結果

問題 No.1937 Various Tournament
ユーザー rin204rin204
提出日時 2022-05-13 22:10:10
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 838 ms / 2,000 ms
コード長 1,310 bytes
コンパイル時間 273 ms
使用メモリ 95,648 KB
最終ジャッジ日時 2023-02-21 14:47:01
合計ジャッジ時間 29,925 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 94 ms
80,380 KB
testcase_01 AC 804 ms
95,368 KB
testcase_02 AC 808 ms
95,552 KB
testcase_03 AC 812 ms
95,452 KB
testcase_04 AC 824 ms
95,224 KB
testcase_05 AC 114 ms
81,016 KB
testcase_06 AC 814 ms
95,404 KB
testcase_07 AC 838 ms
95,608 KB
testcase_08 AC 113 ms
80,916 KB
testcase_09 AC 828 ms
95,496 KB
testcase_10 AC 114 ms
81,188 KB
testcase_11 AC 818 ms
95,468 KB
testcase_12 AC 824 ms
95,648 KB
testcase_13 AC 828 ms
95,372 KB
testcase_14 AC 838 ms
95,452 KB
testcase_15 AC 835 ms
95,412 KB
testcase_16 AC 817 ms
95,472 KB
testcase_17 AC 811 ms
95,644 KB
testcase_18 AC 825 ms
95,476 KB
testcase_19 AC 815 ms
95,432 KB
testcase_20 AC 114 ms
81,196 KB
testcase_21 AC 95 ms
80,668 KB
testcase_22 AC 820 ms
95,440 KB
testcase_23 AC 805 ms
95,460 KB
testcase_24 AC 814 ms
95,292 KB
testcase_25 AC 115 ms
81,276 KB
testcase_26 AC 815 ms
95,416 KB
testcase_27 AC 95 ms
80,592 KB
testcase_28 AC 810 ms
95,148 KB
testcase_29 AC 113 ms
80,764 KB
testcase_30 AC 825 ms
95,184 KB
testcase_31 AC 825 ms
95,108 KB
testcase_32 AC 829 ms
95,468 KB
testcase_33 AC 826 ms
95,308 KB
testcase_34 AC 822 ms
95,140 KB
testcase_35 AC 835 ms
95,224 KB
testcase_36 AC 818 ms
95,460 KB
testcase_37 AC 115 ms
80,884 KB
testcase_38 AC 114 ms
80,760 KB
testcase_39 AC 820 ms
95,224 KB
testcase_40 AC 113 ms
81,196 KB
testcase_41 AC 115 ms
81,036 KB
testcase_42 AC 825 ms
95,220 KB
testcase_43 AC 114 ms
81,024 KB
testcase_44 AC 95 ms
80,832 KB
testcase_45 AC 829 ms
95,220 KB
testcase_46 AC 116 ms
81,212 KB
testcase_47 AC 95 ms
80,356 KB
testcase_48 AC 95 ms
80,384 KB
testcase_49 AC 113 ms
81,108 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