結果

問題 No.698 ペアでチームを作ろう
ユーザー moharan627moharan627
提出日時 2021-07-28 14:43:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 131 ms / 1,000 ms
コード長 1,002 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 87,284 KB
実行使用メモリ 77,632 KB
最終ジャッジ日時 2023-10-11 12:30:28
合計ジャッジ時間 3,294 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,656 KB
testcase_01 AC 74 ms
71,388 KB
testcase_02 AC 92 ms
77,000 KB
testcase_03 AC 76 ms
71,460 KB
testcase_04 AC 111 ms
77,632 KB
testcase_05 AC 121 ms
77,384 KB
testcase_06 AC 125 ms
77,412 KB
testcase_07 AC 129 ms
77,476 KB
testcase_08 AC 129 ms
77,536 KB
testcase_09 AC 127 ms
77,388 KB
testcase_10 AC 129 ms
77,524 KB
testcase_11 AC 130 ms
77,536 KB
testcase_12 AC 129 ms
77,568 KB
testcase_13 AC 130 ms
77,380 KB
testcase_14 AC 131 ms
77,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#sys.setrecursionlimit(10 ** 6)
INF = float('inf')
#10**20,2**63に変えるのもあり
MOD = 10**9 + 7
MOD2 = 998244353

def solve():
    def II(): return int(sys.stdin.readline())
    def LI(): return list(map(int, sys.stdin.readline().split()))
    def LC(): return list(input())
    def IC(): return [int(c) for c in input()]
    def MI(): return map(int, sys.stdin.readline().split())
    N = II()
    A = LI()
    DP = [0]*(2 ** N)
    for S in range(2 ** N):
        if bin(S)[2:].count("1") %2 == 1:continue
        #奇数のペアはないのでスルー。
        for a in range(N):  # ペアのうち一人のa
            for b in range(N):# ペアのうち一人のb
                if a == b:continue#まぁ、これはおかしい
                if (S >> a & 1) or (S >> b & 1):continue#すでにペアになってる人は使えない。
                DP[S | (1 << a) | (1<<b)] = max(DP[S] + (A[a] ^ A[b]), DP[S | (1 << a) | (1<<b)])
    print(DP[S])
    return
solve()
0