結果

問題 No.698 ペアでチームを作ろう
ユーザー lam6er
提出日時 2025-03-20 20:22:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 72 ms / 1,000 ms
コード長 686 bytes
コンパイル時間 342 ms
コンパイル使用メモリ 82,360 KB
実行使用メモリ 71,088 KB
最終ジャッジ日時 2025-03-20 20:24:28
合計ジャッジ時間 1,616 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import lru_cache

n = int(input())
a = list(map(int, input().split()))

@lru_cache(maxsize=None)
def dfs(mask):
    if mask == (1 << n) - 1:
        return 0
    # Find the first unpaired player
    for i in range(n):
        if not (mask & (1 << i)):
            first = i
            break
    max_total = 0
    # Pair the first with all possible others
    for j in range(first + 1, n):
        if not (mask & (1 << j)):
            new_mask = mask | (1 << first) | (1 << j)
            current_xor = a[first] ^ a[j]
            total = current_xor + dfs(new_mask)
            if total > max_total:
                max_total = total
    return max_total

print(dfs(0))
0