結果
| 問題 | 
                            No.699 ペアでチームを作ろう2
                             | 
                    
| ユーザー | 
                             | 
                    
| 提出日時 | 2022-12-20 16:01:00 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 7 ms / 1,000 ms | 
| コード長 | 529 bytes | 
| コンパイル時間 | 1,693 ms | 
| コンパイル使用メモリ | 169,800 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-11-18 01:51:57 | 
| 合計ジャッジ時間 | 2,338 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 12 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(auto &&v:a)cin >> v;
  function<int(int,int)> dfs = [&](int S, int v){
    if(__builtin_popcount(S) == n)return v;
    int ans = 0;
    for(int i = 0; i < n; i++){
      if(S >> i & 1)continue;
      S |= 1 << i;
      for(int j = i + 1; j < n; j++){
        if(S >> j & 1)continue;
        ans = max(ans, dfs(S | (1 << j), v ^ (a[i] + a[j])));
      }
      break;
    }
    return ans;
  };
  cout << dfs(0, 0) << '\n';
}