結果

問題 No.698 ペアでチームを作ろう
ユーザー Riris
提出日時 2025-09-23 21:47:47
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 16 ms / 1,000 ms
コード長 2,639 bytes
コンパイル時間 2,107 ms
コンパイル使用メモリ 203,684 KB
実行使用メモリ 15,616 KB
最終ジャッジ日時 2025-09-23 21:47:51
合計ジャッジ時間 3,407 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif

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

using ll = long long;            // 2^63-1まで 負の値は可
using ull = unsigned long long;  // 0<= ull <=2^64-1の範囲 負の値は不可
using lll = __int128_t;  // 1e38まで 計算に使う場合はなるべく型を合わせる
using vl = vector<ll>;
using vs = vector<string>;
using vvl = vector<vl>;
using P = pair<ll, ll>;
using G = vector<vl>;
template <typename T>
using MNPQ = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using MXPQ = priority_queue<T, vector<T>, less<T>>;

#define rep(i, n) for (ll i = 0; i < n; i++)
#define srep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (ll i = s; i > n; i--)
#define nall(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define lwb(a, x) (ll)(lower_bound(nall(a), x) - a.begin())
#define upb(a, x) (ll)(upper_bound(nall(a), x) - a.begin())
#define vunique(v) v.erase(unique(nall(v)), v.end())
#define pb push_back
#define YN(flg) cout << (flg ? "Yes" : "No") << endl
#define debug(x) cerr << #x << " = " << x << endl;
const ll INF = 2e18;

template <typename T>
void vprint(vector<T>& a)
{
    for (auto& x : a) cout << x << ' ';
    cout << endl;
}
template <typename T>
void vvprint(vector<vector<T>>& a)
{
    for (auto& row : a) vprint(row);
}
template <typename K, typename V>
void mapprint(map<K, V>& a)
{
    for (auto ite = a.begin(); ite != a.end(); ite++)
    {
        cout << "{key:" << ite->first << ", item:" << a[ite->first] << "} ";
    }
    cout << endl;
}
bool out_grid(ll x, ll y, ll h, ll w)
{
    return !(0 <= x && x < h && 0 <= y && y < w);
}
// デバッグ用
void print128(lll x)
{
    string res = "";
    while (x > 0)
    {
        res += '0' + x % 10;
        x /= 10;
    }
    reverse(nall(res));
    cout << res << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n;
    cin >> n;
    vl a(n);
    rep(i, n) cin >> a[i];

    vector<ll> arr(1 << n);
    vector<ll> b;
    rep(i, n) srep(j, i + 1, n)
    {
        arr[(1 << i) + (1 << j)] = a[i] ^ a[j];
        b.push_back((1 << i) + (1 << j));
    }

    vector<vector<ll>> dp(b.size() + 1, vector<ll>(1 << n));
    rep(i, b.size())
    {
        rep(j, 1 << n)
        {
            dp[i + 1][j] = dp[i][j];
            if ((j & b[i]) == b[i])
                chmax(dp[i + 1][j], dp[i][j & ~b[i]] + arr[b[i]]);
        }
    }

    cout << dp.back().back() << endl;

    return 0;
}
0