結果

問題 No.698 ペアでチームを作ろう
ユーザー H20
提出日時 2021-05-27 10:31:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 84 ms / 1,000 ms
コード長 498 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 82,792 KB
実行使用メモリ 76,216 KB
最終ジャッジ日時 2024-11-06 06:14:02
合計ジャッジ時間 1,933 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    N = int(input())
    A = list(map(int,input().split()))
    dp = [0]*(1<<N)
    for s in range(0, 1<<N):#集合を添字の小さい順に試す
        for i in range(N):#全ての要素のペアを考える
            for j in range(i+1,N):
                if ((s>>i)&1)==0 and ((s>>j)&1)==0:#i in not s and j in not s
                    if dp[s+(1<<i)+(1<<j)]<dp[s]+(A[i]^A[j]):
                        dp[s+(1<<i)+(1<<j)]=dp[s]+(A[i]^A[j])
    return dp[-1]
print(main())    
0