結果

問題 No.1560 majority x majority
ユーザー H3PO4H3PO4
提出日時 2022-11-27 16:50:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 628 ms / 2,000 ms
コード長 637 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 64,080 KB
最終ジャッジ日時 2024-04-15 00:10:34
合計ジャッジ時間 18,774 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 628 ms
63,744 KB
testcase_01 AC 623 ms
64,080 KB
testcase_02 AC 513 ms
44,108 KB
testcase_03 AC 621 ms
62,736 KB
testcase_04 AC 612 ms
60,456 KB
testcase_05 AC 616 ms
60,668 KB
testcase_06 AC 561 ms
45,636 KB
testcase_07 AC 529 ms
44,608 KB
testcase_08 AC 567 ms
52,252 KB
testcase_09 AC 566 ms
46,960 KB
testcase_10 AC 519 ms
44,616 KB
testcase_11 AC 525 ms
43,972 KB
testcase_12 AC 523 ms
44,364 KB
testcase_13 AC 527 ms
44,228 KB
testcase_14 AC 533 ms
44,104 KB
testcase_15 AC 560 ms
46,664 KB
testcase_16 AC 524 ms
44,516 KB
testcase_17 AC 582 ms
52,028 KB
testcase_18 AC 540 ms
45,508 KB
testcase_19 AC 521 ms
44,360 KB
testcase_20 AC 522 ms
44,356 KB
testcase_21 AC 520 ms
44,232 KB
testcase_22 AC 544 ms
46,916 KB
testcase_23 AC 519 ms
43,968 KB
testcase_24 AC 517 ms
44,360 KB
testcase_25 AC 543 ms
47,044 KB
testcase_26 AC 516 ms
44,204 KB
testcase_27 AC 514 ms
44,240 KB
testcase_28 AC 513 ms
44,096 KB
testcase_29 AC 515 ms
44,364 KB
testcase_30 AC 520 ms
44,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import numpy as np

input = sys.stdin.buffer.readline

N, M = map(int, input().split())
S = np.array(tuple(tuple(map(int, input().split())) for _ in range(N)), dtype=bool)

dp = [0] * (1 << M)
alive = np.zeros((1 << M, N), dtype=bool)
dp[0] = 1
alive[0] = True

for i in range(M):
    for b in range(1 << i):
        alive[b | (1 << i)] = alive[b] & S[:, i]
alive_count = np.count_nonzero(alive, axis=1)

for b in range(1 << M):
    for i in range(M):
        if (b >> i) & 1:
            continue
        c = b | (1 << i)
        if alive_count[c] >= alive_count[b] - alive_count[c]:
            dp[c] += dp[b]
print(dp[-1])
0