結果

問題 No.698 ペアでチームを作ろう
ユーザー tktk_snsntktk_snsn
提出日時 2021-01-25 10:19:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 113 ms / 1,000 ms
コード長 737 bytes
コンパイル時間 1,445 ms
コンパイル使用メモリ 86,832 KB
実行使用メモリ 77,440 KB
最終ジャッジ日時 2023-09-03 21:27:43
合計ジャッジ時間 2,779 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,356 KB
testcase_01 AC 75 ms
71,076 KB
testcase_02 AC 93 ms
76,336 KB
testcase_03 AC 75 ms
71,296 KB
testcase_04 AC 97 ms
76,300 KB
testcase_05 AC 108 ms
76,868 KB
testcase_06 AC 112 ms
77,084 KB
testcase_07 AC 103 ms
76,400 KB
testcase_08 AC 106 ms
76,548 KB
testcase_09 AC 113 ms
77,440 KB
testcase_10 AC 109 ms
77,284 KB
testcase_11 AC 105 ms
76,384 KB
testcase_12 AC 101 ms
76,288 KB
testcase_13 AC 100 ms
76,344 KB
testcase_14 AC 107 ms
77,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


def pop_count(T):
    T = (T & 0x55555555) + ((T >> 1) & 0x55555555)
    T = (T & 0x33333333) + ((T >> 2) & 0x33333333)
    T = (T & 0x0F0F0F0F) + ((T >> 4) & 0x0F0F0F0F)
    T = (T & 0x00FF00FF) + ((T >> 8) & 0x00FF00FF)
    T = (T & 0x0000FFFF) + ((T >> 16) & 0x0000FFFF)
    return T


dp = [0] * (1 << N)
for S in range(1 << N):
    if pop_count(S) % 2 == 1:
        continue
    for i in range(N - 1):
        if ~(S >> i) & 1:
            for j in range(i + 1, N):
                if ~(S >> j) & 1:
                    U = S ^ (1 << i) ^ (1 << j)
                    if dp[U] < dp[S] + (A[i] ^ A[j]):
                        dp[U] = dp[S] + (A[i] ^ A[j])
print(dp[(1 << N)-1])
0