結果

問題 No.699 ペアでチームを作ろう2
ユーザー youthfuldays072youthfuldays072
提出日時 2018-12-10 05:48:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,519 bytes
コンパイル時間 751 ms
コンパイル使用メモリ 100,784 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 22:05:44
合計ジャッジ時間 1,922 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18


int dfs(int rem, int score, const vector<int>& As) {
	//全員とりおわった
	if (rem == 0) return score;


	int record = 0;

	//一人目を最終ビット以外から選ぶ
	//例えばAsが0123の4つだったら<4-1=3;
	//012の3つが候補

	for (int i = 0; i < As.size() - 1; ++i) {

		//残りの人間の集合から選ぶのでビットが立ってなければ飛ばす
		if ((rem & (1 << i)) == 0) continue;

		//一人目に選んだ人を集合から取り除く
		rem ^= (1 << i);

		//iとペアにする人をi以外から選ぶ
		for (int j = i + 1; j < As.size(); ++j) {
			//残りの人間の集合から選ぶのでビットが立ってなければ飛ばす
			if ((rem & (1 << j)) == 0) continue;

			//選んだiに対しての可能性を全部試して
			//最大値を更新していく
			record = max(record, dfs(rem ^ (1 << j), score ^ (As[i] + As[j]), As));
		}

		//jを選んだときに取り除かないといけない。
		//ただ、iをとった状態はまだ残しておきたいので
		//関数に値渡しして、コピーに対して取り除くという操作をする

		//その副作用でjのループが終わってもremが残ってしまう。
		//ここでbreakしないと探索は終わっているのにまたiを選びにいってしまう

	}
	return record;
}


int main() {
	int N;
	cin >> N;
	vector<int> As(N);
	for (auto & a : As) cin >> a;

	//1111全部並べた。選んだ状態を保持しておいて、選んだら
	//1をとって、次にいく。
	int rem = (1 << N) - 1;
	cout << dfs(rem, 0, As) << endl;

	return 0;
}
0