結果

問題 No.699 ペアでチームを作ろう2
ユーザー 0w10w1
提出日時 2018-10-21 00:55:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 139 ms / 1,000 ms
コード長 625 bytes
コンパイル時間 2,229 ms
コンパイル使用メモリ 210,148 KB
実行使用メモリ 10,368 KB
最終ジャッジ日時 2024-04-29 20:06:19
合計ジャッジ時間 3,916 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_04 AC 10 ms
5,376 KB
testcase_05 AC 24 ms
5,376 KB
testcase_06 AC 25 ms
5,376 KB
testcase_07 AC 133 ms
9,856 KB
testcase_08 AC 133 ms
10,240 KB
testcase_09 AC 139 ms
10,240 KB
testcase_10 AC 136 ms
9,984 KB
testcase_11 AC 139 ms
10,240 KB
testcase_12 AC 134 ms
10,112 KB
testcase_13 AC 138 ms
10,368 KB
testcase_14 AC 133 ms
10,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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