結果

問題 No.698 ペアでチームを作ろう
ユーザー みあえみあえ
提出日時 2024-04-01 01:01:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 142 ms / 1,000 ms
コード長 553 bytes
コンパイル時間 1,986 ms
コンパイル使用メモリ 81,444 KB
実行使用メモリ 75,664 KB
最終ジャッジ日時 2024-04-01 01:01:30
合計ジャッジ時間 4,494 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 57 ms
68,472 KB
testcase_03 AC 36 ms
53,460 KB
testcase_04 AC 80 ms
75,536 KB
testcase_05 AC 137 ms
75,640 KB
testcase_06 AC 140 ms
75,664 KB
testcase_07 AC 138 ms
75,664 KB
testcase_08 AC 140 ms
75,664 KB
testcase_09 AC 141 ms
75,664 KB
testcase_10 AC 140 ms
75,664 KB
testcase_11 AC 138 ms
75,664 KB
testcase_12 AC 141 ms
75,664 KB
testcase_13 AC 142 ms
75,664 KB
testcase_14 AC 138 ms
75,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import combinations


def solve(N, A):
    dp = [-float("inf")] * (1 << N)
    dp[0] = 0
    for V in range(1 << N):
        for i, j in combinations(range(N), 2):
            ai = A[i]
            aj = A[j]
            if not ((V >> i) & 1) and not ((V >> j) & 1):
                VV = V | (1 << i) | (1 << j)
                dp[VV] = max(dp[VV], dp[V] + (ai ^ aj))

    return dp[-1]


def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = solve(N, A)
    print(ans)


if __name__ == "__main__":
    main()
0