結果
| 問題 |
No.1912 Get together 2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-09 18:35:14 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 856 bytes |
| コンパイル時間 | 549 ms |
| コンパイル使用メモリ | 82,140 KB |
| 実行使用メモリ | 107,372 KB |
| 最終ジャッジ日時 | 2024-06-24 01:20:54 |
| 合計ジャッジ時間 | 6,829 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 TLE * 1 -- * 22 |
ソースコード
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))