結果

問題 No.698 ペアでチームを作ろう
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2019-08-26 20:15:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 1,000 ms
コード長 1,223 bytes
コンパイル時間 1,611 ms
コンパイル使用メモリ 166,848 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-25 15:07:52
合計ジャッジ時間 2,281 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = MOD - 1;
const ll LLINF = 4e18;

int bit_count(int n) {
    int cnt = 0;
    while (n != 0) {
        if (n % 2 == 1) cnt++;
        n >>= 1;
    }
    return cnt;
}

// まだ使っってないものがS
ll power(int S, int n,vector<ll>& dp,const vector<int>& a) {
    if (dp[S] >= 0) return dp[S];
    if (S == (1<<n)-1) return dp[S] = 0;
    ll res = 0;
    REP(i, n) {
        REP(j, n) {
            if (i == j) continue;
            // 既に使われている
            if ((S | (1 << i)) == S || (S | (1 << j)) == S) continue;
            res = max(res, power(S | (1 << i) | (1 << j), n, dp,a) + (a[i] ^ a[j]));
        }
    }
    return dp[S] = res;
}

int main() {
    int n; cin >> n;
    vector<ll> dp(1 << n,-1);
    vector<int> a(n);
    REP(i, n) {
        cin >> a[i];
    }
    cout << power(0, n, dp, a) << endl;
    getchar(); getchar();
}
0