結果

問題 No.699 ペアでチームを作ろう2
ユーザー 0w1
提出日時 2018-10-21 00:55:33
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 102 ms / 1,000 ms
コード長 625 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,984 ms
コンパイル使用メモリ 219,560 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2026-06-07 02:29:57
合計ジャッジ時間 3,089 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

signed main() {
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  vector<int> A(N);
  for (int i = 0; i < N; ++i) cin >> A[i];

  function<set<int>(int)> search = [&](int s) {
    if (s + 1 == 1 << N) return set<int>({0});
    int l = __builtin_ctz(~s);
    set<int> res;
    for (int i = 0; i < N; ++i) {
      if (~s >> i & 1) {
        if (i != l) {
          auto v = search(s | 1 << i | 1 << l);
          for (auto u : v) res.emplace(A[i] + A[l] ^ u);
        }
      }
    }
    return res;
  };

  auto v = search(0);
  cout << *v.rbegin() << endl;

  return 0;
}
0