結果

問題 No.699 ペアでチームを作ろう2
ユーザー siman
提出日時 2021-10-17 18:10:29
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 6 ms / 1,000 ms
コード長 842 bytes
コンパイル時間 1,173 ms
コンパイル使用メモリ 140,020 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-17 19:43:18
合計ジャッジ時間 1,864 ms
ジャッジサーバーID
(参考情報)
judge1 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

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