結果

問題 No.699 ペアでチームを作ろう2
ユーザー troro_kelptroro_kelp
提出日時 2019-04-10 14:40:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,560 bytes
コンパイル時間 1,453 ms
コンパイル使用メモリ 102,072 KB
実行使用メモリ 8,768 KB
最終ジャッジ日時 2023-09-21 11:27:02
合計ジャッジ時間 4,938 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
using ld = long double;

int arr[15];
int N;
int maxV = 0;

void dfs(int d, stack<int> st, bool used[15])
{
    if (d == N)
    {
        int sum = 0;
        while (st.size())
        {
            sum = sum ^ st.top();
            st.pop();
        }
        maxV = max(maxV, sum);
        return;
    }

    for (int i = 0; i < N; ++i)
    {
        if (!used[i])
        {
            used[i] = true;
            if (d % 2 == 1)
            {
                int n = st.top();
                st.pop();
                st.push(n + arr[i]);

                dfs(d + 1, st, used);

                st.pop();
                st.push(n);
            }
            else
            {
                st.push(arr[i]);
                dfs(d + 1, st, used);
                st.pop();
            }
            used[i] = false;
        }
    }
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(5);

    cin >> N;
    for (int i = 0; i < N; ++i)
        cin >> arr[i];

    bool used[15];
    for (int i = 0; i < N; ++i)
        used[i] = false;

    stack<int> st;
    dfs(0, st, used);

    cout << maxV << endl;
    return 0;
}
0