結果

問題 No.698 ペアでチームを作ろう
ユーザー ptotq
提出日時 2020-03-24 22:29:40
言語 Python3
(3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 542 ms / 1,000 ms
+ 465µs
コード長 487 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 56 ms
コンパイル使用メモリ 14,848 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2026-10-10 02:16:07
合計ジャッジ時間 6,747 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
from itertools import combinations
input = sys.stdin.readline

N = int(input())
power = list(map(int, input().split()))

dp = [0]*(1 << N)

for bitset in range(1 << N):
    for (p1, power1), (p2, power2) in combinations(enumerate(power), r=2):
        if ((1 << p1) | (1 << p2)) & bitset:
            continue
        dp[bitset | (1 << p1) | (1 << p2)] = max(
            dp[bitset | (1 << p1) | (1 << p2)],
            dp[bitset] + (power1 ^ power2)
        )

print(dp[-1])
0