結果

問題 No.1560 majority x majority
ユーザー Kiri8128Kiri8128
提出日時 2021-06-25 22:16:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 207 ms / 2,000 ms
コード長 1,190 bytes
コンパイル時間 1,992 ms
コンパイル使用メモリ 86,880 KB
実行使用メモリ 83,116 KB
最終ジャッジ日時 2023-09-07 14:36:09
合計ジャッジ時間 5,504 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 205 ms
80,412 KB
testcase_01 AC 207 ms
83,116 KB
testcase_02 AC 70 ms
71,456 KB
testcase_03 AC 186 ms
80,856 KB
testcase_04 AC 179 ms
79,696 KB
testcase_05 AC 185 ms
81,896 KB
testcase_06 AC 110 ms
77,920 KB
testcase_07 AC 96 ms
76,576 KB
testcase_08 AC 148 ms
80,164 KB
testcase_09 AC 118 ms
78,040 KB
testcase_10 AC 94 ms
76,972 KB
testcase_11 AC 104 ms
78,492 KB
testcase_12 AC 91 ms
77,116 KB
testcase_13 AC 104 ms
78,076 KB
testcase_14 AC 95 ms
76,776 KB
testcase_15 AC 114 ms
78,116 KB
testcase_16 AC 97 ms
76,976 KB
testcase_17 AC 145 ms
80,000 KB
testcase_18 AC 109 ms
78,768 KB
testcase_19 AC 94 ms
76,676 KB
testcase_20 AC 92 ms
76,676 KB
testcase_21 AC 96 ms
77,012 KB
testcase_22 AC 121 ms
79,224 KB
testcase_23 AC 98 ms
76,848 KB
testcase_24 AC 93 ms
76,888 KB
testcase_25 AC 124 ms
78,680 KB
testcase_26 AC 74 ms
71,368 KB
testcase_27 AC 74 ms
71,060 KB
testcase_28 AC 73 ms
71,440 KB
testcase_29 AC 72 ms
71,572 KB
testcase_30 AC 80 ms
76,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

NN = 16
KK = (1 << (1 << NN)) - 1
I0 = KK // 3
I1 = KK // 5
I2 = KK // 17
I3 = KK // 257

def popcount(x):
    x -= (x >> 1) & I0
    x = (x & I1) + ((x >> 2) & I1)
    x = (x + (x >> 4)) & I2
    x = (x + (x >> 8)) & I3
    x += x >> 16
    x += x >> 32
    x += x >> 64
    x += x >> 128
    x += x >> 256
    x += x >> 512
    x += x >> 1024
    x += x >> 2048
    x += x >> 4096
    return x & 0xffff

N, M = map(int, input().split())
I = [[] for _ in range(M)]
IV = {1 << i: i for i in range(M)}
for i in range(N):
    for j, a in enumerate(input().split()):
        I[j].append(a)
A = []
for ii in I:
    A.append(int("0" + "".join(ii[::-1]), 2))

mmm = (1 << N) - 1
AND = [0] * (1 << M)
PC = [0] * (1 << M)
AND[0] = mmm
PC[0] = N
ANS = [0] * (1 << M)
ANS[0] = 1
for i in range(1, 1 << M):
    a = i & -i
    if a == i:
        AND[i] = A[IV[a]]
        PC[i] = popcount(AND[i])
    else:
        AND[i] = AND[a] & AND[i^a]
        PC[i] = popcount(AND[i])
    
    pc = PC[i]
    ans = 0
    for j in range(N):
        if i >> j & 1:
            ij = i ^ (1 << j)
            ppc = PC[ij]
            if pc * 2 >= ppc:
                ans += ANS[ij]
    ANS[i] = ans

print(ANS[-1])
0