結果

問題 No.698 ペアでチームを作ろう
ユーザー ptotqptotq
提出日時 2020-03-24 22:29:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 832 ms / 1,000 ms
コード長 487 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 10,692 KB
実行使用メモリ 9,156 KB
最終ジャッジ日時 2023-08-30 08:57:44
合計ジャッジ時間 9,298 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,108 KB
testcase_01 AC 16 ms
8,256 KB
testcase_02 AC 40 ms
8,240 KB
testcase_03 AC 17 ms
8,120 KB
testcase_04 AC 164 ms
8,688 KB
testcase_05 AC 779 ms
8,572 KB
testcase_06 AC 794 ms
8,480 KB
testcase_07 AC 799 ms
9,144 KB
testcase_08 AC 789 ms
9,132 KB
testcase_09 AC 800 ms
9,088 KB
testcase_10 AC 812 ms
9,132 KB
testcase_11 AC 816 ms
9,156 KB
testcase_12 AC 805 ms
9,016 KB
testcase_13 AC 789 ms
9,084 KB
testcase_14 AC 832 ms
9,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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