結果

問題 No.698 ペアでチームを作ろう
ユーザー pianonekopianoneko
提出日時 2019-03-12 17:46:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 1,000 ms
コード長 708 bytes
コンパイル時間 2,636 ms
コンパイル使用メモリ 164,120 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 20:22:49
合計ジャッジ時間 2,372 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define llINF ((long long)1e18)
#define iINF ((int)1e9)
#define ALL(obj) obj.begin(), obj.end()

using namespace std;

int N, A[14], dp[1 << 14];

int rec(int S) {
    if (dp[S] != -1) {
        return dp[S];
    }

    if (S == (1 << N) - 1) {
        return 0;
    }

    int res = 0;

    REP(i, N) {
        if ((S >> i) & 1) continue;
        REP(j, N) {
            if ((S >> j) & 1) continue;
            res = max(res, rec(S | (1 << i) | (1 << j)) + (A[i] ^ A[j]));
        }
    }
    return dp[S] = res;
}

int main() {
    cin >> N;
    REP(i, N) { cin >> A[i]; }
    memset(dp, -1, sizeof(dp));
    cout << rec(0) << endl;
}
0