結果
| 問題 | 
                            No.698 ペアでチームを作ろう
                             | 
                    
| ユーザー | 
                             efunyo
                         | 
                    
| 提出日時 | 2020-03-24 22:12:04 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 255 ms / 1,000 ms | 
| コード長 | 1,405 bytes | 
| コンパイル時間 | 170 ms | 
| コンパイル使用メモリ | 12,288 KB | 
| 実行使用メモリ | 10,880 KB | 
| 最終ジャッジ日時 | 2025-01-01 18:35:42 | 
| 合計ジャッジ時間 | 3,465 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 12 | 
ソースコード
#https://yukicoder.me/problems/no/698
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter
    #inf = 10**17
    #mod = 10**9 + 7
    N = int(input())
    a = list(map(int, input().split()))
    #dp[s]:sは作成済みのペア
    #         dp[s]はその時の戦闘力
    dp = [0]*(1<<N)
    for s in range(1<<N):
        #1が奇数個の場合はスルー
        cnt = 0
        for i in range(N):
            if (s>>i) & 1:
                cnt += 1
        if cnt%2 != 0:
            continue
        
        #誰がペアを作るか
        for i in range(N):
            cur = 0
            if (s>>i) & 1:
                continue
            #片方の戦闘力
            cur = a[i]
            new_s = s|1<<i
            dp[new_s] = dp[s]
            #ペアを作る相手とその時の戦闘力
            for j in range(N):
                if (new_s>>j) & 1:
                    continue
                dp[new_s|1<<j] = max(dp[new_s|1<<j], dp[new_s]+(cur^a[j]))
    print(dp[-1])
if __name__ == '__main__':
    main()
            
            
            
        
            
efunyo