結果

問題 No.2713 Just Solitaire
ユーザー koncha
提出日時 2024-03-31 15:23:58
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,354 bytes
コンパイル時間 473 ms
コンパイル使用メモリ 82,044 KB
実行使用メモリ 88,976 KB
最終ジャッジ日時 2024-09-30 20:38:30
合計ジャッジ時間 4,098 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 1 WA * 1 TLE * 1 -- * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

def solver(total, current, card):
    global answer
    if tuple(sorted(card)) in memo:
        return

    memo.add(tuple(sorted(card)))
    answer = max(answer, total)

    for x in range(N):
        if x in card:
            card.remove(x)
            total += A[x]
            deletes = current.intersection(inv_cards[x])
            for delete in deletes:
                total -= B[delete]
                current.remove(delete)

            rem = []
            for y in range(N):
                if y in card and not current.intersection(inv_cards[y]):
                    card.remove(y)
                    total += A[y]
                    rem.append(y)

            solver(total, current, card)

            for y in rem:
                card.add(y)
                total -= A[y]

            for delete in deletes:
                total += B[delete]
                current.add(delete)
            total -= A[x]
            card.add(x)


N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

cards = [list(map(lambda x: int(x)-1, input().split()))[1:] for _ in range(M)]
inv_cards = [set() for _ in range(N)]

for x in range(M):
    for c in cards[x]:
        inv_cards[c].add(x)

memo = set()

answer = max(sum(B) - sum(A), 0)

solver(answer, set(range(M)), set(range(N)))


print(answer)
0