結果

問題 No.698 ペアでチームを作ろう
ユーザー rogi52rogi52
提出日時 2022-10-10 05:51:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 1,000 ms
コード長 787 bytes
コンパイル時間 3,584 ms
コンパイル使用メモリ 208,984 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 07:08:44
合計ジャッジ時間 3,512 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

    int ans = -1e9, sum = 0;
    set<int> st;
    rep(i,N) st.insert(i);
    function<void(void)> dfs = [&](void) -> void {
        if(int(st.size()) == 0) {
            ans = max(ans, sum);
        } else {
            int L = *st.begin();
            st.erase(L);
            set<int> R = st;
            for(int x : R) {
                sum += (A[L] ^ A[x]); st.erase(x);
                dfs();
                sum -= (A[L] ^ A[x]); st.insert(x);
            }
            st.insert(L);
        }
    }; dfs();
    cout << ans << endl;
}
0