結果

問題 No.698 ペアでチームを作ろう
ユーザー orange orangeorange orange
提出日時 2023-10-13 01:38:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,225 bytes
コンパイル時間 837 ms
コンパイル使用メモリ 99,296 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-13 01:38:12
合計ジャッジ時間 3,606 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<climits>
#include<set>
#include<map>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<assert.h>
#include<numeric>
#include<bitset>

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
using namespace std;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 62;
const double PI = 2 * acos(0.0);
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return a ? gcd(b % a, a) : b; }

int n;
int A[20];
int dp[20000];
int rec(int S) {
	if (S == 0) return 0;

	int& ret = dp[S];

	if (ret != 0) return ret;


	for (int i = 0; i < n; i++) if (S & 1 << i) {
		for (int j = i + 1; j < n; j++) {
			if (S & 1 << j) {
				int score = A[i] ^ A[j];
				int pair = (1 << i) + (1 << j);
				chmax(ret, rec(S ^ pair) + score);
			}
		}
	}

	return ret;
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> A[i];

	cout << rec((1 << n) - 1) << endl;
}
0