結果
| 問題 |
No.698 ペアでチームを作ろう
|
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 18:41:53 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 70 ms / 1,000 ms |
| コード長 | 686 bytes |
| コンパイル時間 | 175 ms |
| コンパイル使用メモリ | 82,632 KB |
| 実行使用メモリ | 70,756 KB |
| 最終ジャッジ日時 | 2025-03-20 18:41:58 |
| 合計ジャッジ時間 | 1,779 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
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))
lam6er