結果

問題 No.698 ペアでチームを作ろう
ユーザー house_guardhouse_guard
提出日時 2024-01-04 18:33:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 1,000 ms
コード長 1,035 bytes
コンパイル時間 2,072 ms
コンパイル使用メモリ 207,412 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-04 18:33:08
合計ジャッジ時間 3,197 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,j,k) for(int i=j; i<(int)(k); i++)
#define rrep(i,j,k) for(int i=j; i>=(int)(k); i--)
#define Rep(i,j,k) for(ll i=j; i<(ll)(k); i++)
#define RRep(i,j,k) for(ll i=j; i>=(ll)(k); i--)
#define all(v) v.begin(), v.end()

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,0,n) cin >> a[i];

    vector<vector<int>> dp(n,vector<int>((1 << (n)),-1));
    rep(i,0,n){
        rep(j,i+1,n){
            int val=a[i]^a[j];
            dp[1][(1 << i)+(1 << j)]=val;
        }
    }
    rep(i,1,n-2){
        rep(j,0,dp[i].size()){
            if(dp[i][j]>=0){
                bitset<16> r(j);
                rep(k,0,n){
                    rep(l,k+1,n){
                        if(r.test(k) || r.test(l)) continue;
                        dp[i+2][j+(1 << k)+(1 << l)]=max(dp[i+2][j+(1 << k)+(1 << l)],dp[i][j]+(a[k]^a[l]));
                    }
                }
            }
        }
    }
    
    cout << dp[n-1][(1 << (n))-1] << endl;
}
0