結果

問題 No.1912 Get together 2
ユーザー chineristACchineristAC
提出日時 2021-10-06 18:33:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 920 ms / 2,000 ms
コード長 956 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 109,676 KB
最終ジャッジ日時 2023-09-06 06:43:10
合計ジャッジ時間 18,988 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,308 KB
testcase_01 AC 67 ms
71,184 KB
testcase_02 AC 66 ms
71,188 KB
testcase_03 AC 75 ms
76,316 KB
testcase_04 AC 67 ms
71,488 KB
testcase_05 AC 68 ms
71,400 KB
testcase_06 AC 66 ms
71,504 KB
testcase_07 AC 77 ms
76,320 KB
testcase_08 AC 116 ms
81,116 KB
testcase_09 AC 108 ms
79,620 KB
testcase_10 AC 120 ms
82,940 KB
testcase_11 AC 111 ms
80,732 KB
testcase_12 AC 128 ms
82,964 KB
testcase_13 AC 920 ms
109,528 KB
testcase_14 AC 916 ms
109,624 KB
testcase_15 AC 906 ms
109,460 KB
testcase_16 AC 919 ms
109,536 KB
testcase_17 AC 906 ms
109,676 KB
testcase_18 AC 890 ms
109,604 KB
testcase_19 AC 883 ms
109,532 KB
testcase_20 AC 877 ms
109,632 KB
testcase_21 AC 917 ms
109,624 KB
testcase_22 AC 913 ms
109,600 KB
testcase_23 AC 864 ms
109,536 KB
testcase_24 AC 859 ms
109,364 KB
testcase_25 AC 860 ms
109,488 KB
testcase_26 AC 876 ms
109,536 KB
testcase_27 AC 862 ms
109,584 KB
testcase_28 AC 142 ms
91,512 KB
testcase_29 AC 130 ms
91,308 KB
testcase_30 AC 140 ms
91,676 KB
testcase_31 AC 128 ms
91,264 KB
testcase_32 AC 127 ms
91,284 KB
testcase_33 AC 873 ms
109,624 KB
testcase_34 AC 71 ms
71,152 KB
testcase_35 AC 879 ms
109,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def zeta_to_small(N,A):
    res = [a for a in A]
    for i in range(N):
        t = 2**i
        for j in range(1<<N):
            if j&t:
                res[j-t] += res[j]
    return res

def solve(N,M,V,S):
    box = [0 for i in range(1<<M)]

    for i in range(N):
        t = 0
        for j in range(M):
            if S[i][j]=="x":
                t += 1<<j
        box[t] += V[i]

    zeta_box = zeta_to_small(M,box)

    dp = [0 for S in range(2**M)]
    ALL = 2**M-1
    for S in range(1,2**M):
        done = ALL - S
        for j in range(M):
            if S>>j & 1:
                tmp = zeta_box[done] - zeta_box[done + 2**j]
                dp[S] = max(dp[S],dp[S-2**j]+tmp*tmp)

    return dp[-1]

import sys

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

N,M = map(int,input().split())
V = list(map(int,input().split()))
S = [input() for i in range(N)]
print(solve(N,M,V,S))
0