結果

問題 No.1912 Get together 2
ユーザー shotoyooshotoyoo
提出日時 2022-04-05 00:42:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 761 ms / 2,000 ms
コード長 1,079 bytes
コンパイル時間 326 ms
コンパイル使用メモリ 86,952 KB
実行使用メモリ 108,248 KB
最終ジャッジ日時 2023-09-06 06:43:34
合計ジャッジ時間 15,457 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,272 KB
testcase_01 AC 67 ms
71,136 KB
testcase_02 AC 69 ms
71,148 KB
testcase_03 AC 77 ms
76,528 KB
testcase_04 AC 71 ms
70,984 KB
testcase_05 AC 68 ms
71,304 KB
testcase_06 AC 66 ms
71,392 KB
testcase_07 AC 75 ms
76,852 KB
testcase_08 AC 117 ms
80,188 KB
testcase_09 AC 109 ms
78,348 KB
testcase_10 AC 129 ms
81,960 KB
testcase_11 AC 119 ms
79,784 KB
testcase_12 AC 138 ms
82,128 KB
testcase_13 AC 738 ms
108,016 KB
testcase_14 AC 753 ms
108,084 KB
testcase_15 AC 735 ms
107,952 KB
testcase_16 AC 740 ms
107,924 KB
testcase_17 AC 761 ms
108,024 KB
testcase_18 AC 715 ms
108,248 KB
testcase_19 AC 708 ms
108,160 KB
testcase_20 AC 730 ms
108,012 KB
testcase_21 AC 711 ms
108,092 KB
testcase_22 AC 709 ms
107,924 KB
testcase_23 AC 532 ms
108,220 KB
testcase_24 AC 525 ms
108,072 KB
testcase_25 AC 527 ms
108,084 KB
testcase_26 AC 532 ms
108,176 KB
testcase_27 AC 529 ms
107,960 KB
testcase_28 AC 159 ms
90,436 KB
testcase_29 AC 142 ms
90,424 KB
testcase_30 AC 166 ms
90,400 KB
testcase_31 AC 136 ms
90,516 KB
testcase_32 AC 140 ms
90,372 KB
testcase_33 AC 651 ms
108,208 KB
testcase_34 AC 68 ms
71,136 KB
testcase_35 AC 716 ms
108,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))


def zeta_sub(val, n):
    """
    given: そのbitの出席パターン回数
    compute: 各bitのsubsetについて、countの総和
    """
    # len(val)==2^n
    out = val[:]
    for i in range(n):
        for j in range(1<<n):
            if j>>i&1:
                out[j] += out[j^(1<<i)]
    return out

n,m = list(map(int, input().split()))
assert 1<=n<=10**5 and 1<=m<=20
vs = list(map(int, input().split()))
assert len(vs)==n
vals = [0]*(1<<m)
for i in range(n):
    assert 1<=vs[i]<=10**4
    s = input()
    assert len(s)==m and "o" in s
    b = int(s.replace("o", "1").replace("x", "0")[::-1], 2)
    vals[b] += vs[i]
size = zeta_sub(vals, m)
dp = [0]*(1<<m)
for b in range(1<<m):
    val = dp[b]
    for i in range(m):
        if b>>i&1:
            continue
        nb = b|(1<<i)
        dp[nb] = max(dp[nb], val + (size[nb] - size[b])**2)
ans = dp[(1<<m)-1]
print(ans)
0