結果

問題 No.698 ペアでチームを作ろう
ユーザー yuppe19 😺
提出日時 2018-06-11 00:02:06
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 8 ms / 1,000 ms
コード長 659 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 778 ms
コンパイル使用メモリ 82,100 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2026-03-20 13:40:54
合計ジャッジ時間 1,298 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
using namespace std;
using i64 = long long;

int main(void) {
  int n; scanf("%d", &n);
  vector<int> a(n); // a[n]
  for(int i=0; i<n; ++i) { scanf("%d", &a[i]); }
  // dp[集合] := 最大値
  vector<i64> dp(1<<n); // dp[1<<n]
  for(int mask=0; mask<1<<n; ++mask) {
    for(int p=0; p<n; ++p) {
      if(mask>>p & 1) { continue; }
      for(int q=0; q<n; ++q) {
        if(p == q) { continue; }
        if(mask>>q & 1) { continue; }
        int nmask = mask | 1<<p | 1<<q;
        dp[nmask] = max(dp[nmask], dp[mask] + (a[p] ^ a[q]));
      }
    }
  }
  i64 res = dp[(1<<n)-1];
  printf("%lld\n", res);
  return 0;
}
0