結果

問題 No.698 ペアでチームを作ろう
ユーザー tassei903tassei903
提出日時 2021-05-21 21:40:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 1,000 ms
コード長 951 bytes
コンパイル時間 1,623 ms
コンパイル使用メモリ 159,180 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 14:56:16
合計ジャッジ時間 2,486 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <math.h>

using namespace std;

using ll = long long;
using pp = pair<int,int>;
#define rep(i,n) for(int i = 0;i<n;i++)
#define printv(v) for(auto x : v) cout << x << " "; cout << "\n";    // v の要素を表示
#define printv2(v) for(auto x : v) {printv(x);cout << "\n";};

int N;
int A[14];


int main() { 
    // Input
    cin >> N;
    rep(i, N) cin >> A[i];
    vector<int> dp(1 << N,0);
    rep(i, 1<<N){
        rep(j, N) for (int k = j + 1;k < N; k++){
            if ((i >> j) & (i >> k) & 1){
                //cout << i << j << k << i-(1<<j)-(1<<k) << (A[j]^A[k]) << endl;
                //cout << dp[i] << "#" << dp[i-(1<<j)-(1<<k)] << endl;
                dp[i] = max(dp[i], dp[i-(1<<j)-(1<<k)]+(A[j]^A[k]));
                //cout << i << dp[i] << endl;
            }
        }
    }
    cout << dp[(1<<N)-1] << endl;
    //rep(i,1 << N) cout << dp[i] << endl;
    //rep(i, N) cout << A[i] << endl;
}
0