結果

問題 No.699 ペアでチームを作ろう2
ユーザー simansiman
提出日時 2021-10-17 18:10:29
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 1,000 ms
コード長 842 bytes
コンパイル時間 1,123 ms
コンパイル使用メモリ 131,408 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 22:30:45
合計ジャッジ時間 1,899 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

int N;
vector<ll> A;

int dfs(int cur, int mask, int val) {
  if (mask == (1 << N) - 1) {
    return val;
  }
  int value = 0;

  if (mask >> cur & 1) {
    return dfs(cur + 1, mask, val);
  }

  for (int j = cur + 1; j < N; ++j) {
    if (mask >> j & 1) continue;

    int nmask = mask | (1 << cur) | (1 << j);
    int n_val = val ^ (A[cur] + A[j]);
    int v = dfs(cur + 1, nmask, n_val);
    value = max(value, v);
  }

  return value;
}

int main() {
  cin >> N;

  for (int i = 0; i < N; ++i) {
    ll a;
    cin >> a;
    A.push_back(a);
  }

  cout << dfs(0, 0, 0) << endl;

  return 0;
}
0