結果

問題 No.698 ペアでチームを作ろう
ユーザー Kutimoti_TKutimoti_T
提出日時 2018-06-20 16:20:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 1,000 ms
コード長 741 bytes
コンパイル時間 2,190 ms
コンパイル使用メモリ 147,096 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 07:22:06
合計ジャッジ時間 2,091 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int N;
vector<i64> A;

i64 dp[1 << 15];

int main(){
  cin >> N;
  A.resize(N);
  rep(i,0,N - 1){
    cin >> A[i];
  }

  rep(i,0,(1 << 15) - 1){
    dp[i] = -1e9;
  }
  dp[0] = 0;

  for(int s = 1;s < (1 << N);s++){
    if(__builtin_popcount(s) % 2 == 1) continue;
    for(int i = 0;i < N;i++){
      for(int j = 0;j < N;j++){
        if(i == j) continue;
        if(!(s & (1 << i))) continue;
        if(!(s & (1 << j))) continue;

        int t = s;
        t = t & ~(1 << i);
        t = t & ~(1 << j);

        dp[s] = max(dp[s],dp[t] + (A[i] ^ A[j]));
      }
    }
  }

  cout << dp[(1 << N) - 1] << endl;
}

0