結果

問題 No.699 ペアでチームを作ろう2
ユーザー ooaiu
提出日時 2025-02-12 18:58:00
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 118 ms / 1,000 ms
コード長 895 bytes
コンパイル時間 3,628 ms
コンパイル使用メモリ 281,392 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-02-12 18:58:06
合計ジャッジ時間 5,299 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) (void(0))
#endif
void run_case();
int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int T = 1;
	// cin >> T;
	while (T--) run_case();
	return 0;
}
int N;
int A[14];
ll ans;
void dfs(vector<vector<int>> B, int id) {
	if(id == N) {
		ll sum = 0;
		assert(B.size() == N / 2);
		for(int i = 0; i < B.size(); i++) {
			assert(B[i].size() == 2);
			sum ^= B[i][0] + B[i][1];
		}
		ans = max(ans, sum);
		return;
	}
	for(int i = 0; i < B.size(); i++) {
		if(B[i].size() == 1) {
			B[i].push_back(A[id]);
			dfs(B, id + 1);
			B[i].pop_back();
		}
	}
	if(B.size() < N / 2) {
		B.push_back({A[id]});
		dfs(B, id + 1);
		B.pop_back();
	}
}
void run_case() {
	cin >> N;
	for(int i = 0; i < N; i++) cin >> A[i];
	dfs({}, 0);
	cout << ans << endl;
}
0