結果

問題 No.698 ペアでチームを作ろう
ユーザー kkey000kkey000
提出日時 2023-03-21 20:16:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 1,000 ms
コード長 637 bytes
コンパイル時間 575 ms
コンパイル使用メモリ 69,996 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 18:33:58
合計ジャッジ時間 1,343 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 9 ms
4,348 KB
testcase_06 AC 9 ms
4,348 KB
testcase_07 AC 9 ms
4,348 KB
testcase_08 AC 9 ms
4,348 KB
testcase_09 AC 9 ms
4,348 KB
testcase_10 AC 8 ms
4,348 KB
testcase_11 AC 9 ms
4,348 KB
testcase_12 AC 9 ms
4,348 KB
testcase_13 AC 9 ms
4,348 KB
testcase_14 AC 9 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }

    vector<int> dp(1<<n,0);


    for(int i = 0; i < (1<<n); i++){
        for(int j = 0; j < n; j++){
            if ((i & (1<<j) )!= 0) continue;
            for(int k = 0; k < n; k++){
                if ((i & (1<<k) )!= 0) continue;
                if (j == k) continue ; 
                int new_i= i | (1<<j) | (1<<k);
                dp[new_i] = max(dp[i] + (a[j]^a[k]), dp[new_i]);
            }
        }
    }

    cout <<dp[(1<<n)-1]<<endl;
    return 0;
}
0