結果

問題 No.2713 Just Solitaire
ユーザー konchakoncha
提出日時 2024-03-31 15:23:58
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,354 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 88,104 KB
最終ジャッジ日時 2024-03-31 15:24:03
合計ジャッジ時間 3,765 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,460 KB
testcase_01 AC 35 ms
53,460 KB
testcase_02 AC 47 ms
63,780 KB
testcase_03 WA -
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

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