結果

問題 No.2094 Symmetry
ユーザー Kude
提出日時 2022-10-07 21:45:32
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 916 bytes
コンパイル時間 367 ms
コンパイル使用メモリ 81,884 KB
実行使用メモリ 83,072 KB
最終ジャッジ日時 2024-06-12 06:49:56
合計ジャッジ時間 4,780 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 TLE * 1 -- * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import accumulate
n, k = map(int, input().split())
cnt = sum(input().count('#') for _ in range(2 * n))
INF = 1 << 60
dp = [[-INF] * (cnt + 1) for _ in range(2)]
dp[0][0] = 0
for _ in range(2 * n):
    cs = list(map(int, input().split()))
    cs_sym = list(accumulate(sorted((cs[i] + cs[2 * n - 1 - i] for i in range(n)), reverse=True)))
    cs_sorted = list(accumulate(sorted(cs, reverse=True)))
    for i in range(cnt)[::-1]:
        v = max(dp[0][i], dp[1][i])
        if v != -INF:
            for j, c in enumerate(cs_sorted, i + 1):
                if j > cnt:
                    break
                dp[1][j] = max(dp[1][j], v + c)
        v = dp[0][i]
        if v != -INF:
            for di, c in enumerate(cs_sym, 1):
                j = i + 2 * di
                if j > cnt:
                    break
                dp[0][j] = max(dp[0][j], v + c)
print(max(dp[0][cnt] + k, dp[1][cnt]))
0