結果

問題 No.698 ペアでチームを作ろう
ユーザー kakakakanekokakakakaneko
提出日時 2018-07-23 17:56:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 1,000 ms
コード長 1,642 bytes
コンパイル時間 827 ms
コンパイル使用メモリ 94,112 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 16:25:10
合計ジャッジ時間 2,375 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <stack>
#include <set>
#include <sstream>
#include <iomanip>
#include <limits>
#include <cstring>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<double, double >pd;
typedef pair<string, string> sP;
typedef pair<ll, pair<ll, ll>> PP;


const ll mod = 1e4;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const double eps = 1e-10;
const double PI = 3.14159265358979323846;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

ll n, d[15], dp[1 << 15];

int main() {	
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> d[i];
	}
	for (int i = 0;i < (1 << n);i++) {//訪問状況
		for (int j = 0;j < n;j++) {//j番目のbitが立っているか
			for (int k = j + 1;k < n;k++) {//k番目のbitが立っているか
				if (!(i & 1 << j)) {
					if (!(i & 1 << k)) {
						//どちらも立っていなければ、今まで訪問した最大値と現在見ているペアのXORを足したものと比較
						dp[i + (1 << j) + (1 << k)] = max(dp[i + (1 << j) + (1 << k)], dp[i] + (d[j] ^ d[k]));
					}
				}
			}
		}
	}
	cout << dp[(1 << n) - 1] << endl;//全てのペアができた時の最大値
	return 0;
}

0