結果
問題 |
No.699 ペアでチームを作ろう2
|
ユーザー |
![]() |
提出日時 | 2018-09-06 11:04:21 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 14 ms / 1,000 ms |
コード長 | 1,037 bytes |
コンパイル時間 | 1,885 ms |
コンパイル使用メモリ | 166,152 KB |
実行使用メモリ | 6,816 KB |
最終ジャッジ日時 | 2024-11-21 13:21:44 |
合計ジャッジ時間 | 2,444 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
#include <bits/stdc++.h> using namespace std; using int64 = long long; using uint64 = unsigned long long; const int MAX_N = 14; int N, match[MAX_N]; int64 A[MAX_N]; int64 dfs(int pos) { int64 res = 0; if (pos == N) { for (int i = 0; i < N; i++) { if (match[i] > i) { res ^= A[i] + A[match[i]]; } } return res; } else if (match[pos] != -1) { return dfs(pos + 1); } for (int partner = pos + 1; partner < N; partner++) { if (match[partner] < 0) { match[pos] = partner; match[partner] = pos; res = max(res, dfs(pos + 1)); match[pos] = match[partner] = -1; } } return res; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; } memset(match, -1, sizeof(match)); // O(N(N-1)!!) cout << dfs(0) << endl; return 0; }