結果

問題 No.1912 Get together 2
ユーザー chineristACchineristAC
提出日時 2021-08-09 18:35:14
言語 PyPy3
(7.3.13)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 856 bytes
コンパイル時間 668 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 82,828 KB
最終ジャッジ日時 2023-09-06 06:41:46
合計ジャッジ時間 10,017 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,180 KB
testcase_01 AC 72 ms
71,336 KB
testcase_02 AC 73 ms
75,300 KB
testcase_03 AC 82 ms
75,948 KB
testcase_04 AC 71 ms
71,180 KB
testcase_05 AC 72 ms
71,300 KB
testcase_06 AC 75 ms
75,232 KB
testcase_07 AC 82 ms
76,020 KB
testcase_08 AC 147 ms
81,152 KB
testcase_09 AC 183 ms
79,360 KB
testcase_10 AC 198 ms
82,772 KB
testcase_11 AC 191 ms
80,436 KB
testcase_12 AC 353 ms
82,828 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

    def calc(free_group,o_group):
        res = bit[o_group]
        tmp = free_group
        while tmp:
            res += bit[tmp+o_group]
            tmp = (tmp-1)&free_group
        return res

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

    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