結果
問題 | No.698 ペアでチームを作ろう |
ユーザー | iUXQY9ovagC7T7W |
提出日時 | 2019-12-05 00:58:08 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 12 ms / 1,000 ms |
コード長 | 1,062 bytes |
コンパイル時間 | 545 ms |
コンパイル使用メモリ | 65,660 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-08-21 08:40:42 |
合計ジャッジ時間 | 1,472 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,384 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 3 ms
4,376 KB |
testcase_05 | AC | 12 ms
4,380 KB |
testcase_06 | AC | 11 ms
4,380 KB |
testcase_07 | AC | 12 ms
4,380 KB |
testcase_08 | AC | 11 ms
4,376 KB |
testcase_09 | AC | 11 ms
4,384 KB |
testcase_10 | AC | 11 ms
4,380 KB |
testcase_11 | AC | 11 ms
4,380 KB |
testcase_12 | AC | 11 ms
4,376 KB |
testcase_13 | AC | 11 ms
4,380 KB |
testcase_14 | AC | 12 ms
4,376 KB |
ソースコード
#include<iostream> #include<algorithm> #include<utility> #include<vector> #include<cmath> using namespace std; typedef pair<int, int> P; typedef long long ll; const int INF = 100000000; ll gcd( ll a, ll b ){//最大公約数 ll tmp; if( a < b ) { tmp = a; a = b; b = tmp; } if( b < 1 ) return -1; if( a % b == 0 ) return b; return gcd( b, a % b ); } ll lcm(ll a, ll b){//最小公倍数 return a * b / gcd(a, b); } //入力 int n; int a[20]; int dp[1<<14]; int main(){ cin >> n; for(int i = 0; i < n; i++) cin >> a[i]; for(int before = 0; before < (1 << n); before++){ for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ if(i == j) continue; if(before & (1 << i) || before & (1 << j)) continue; int after = before; after |= (1 << i); after |= (1 << j); dp[after] = max(dp[after], dp[before] + (a[i] ^ a[j])); } } } cout << dp[(1 << n) - 1] << endl; return 0; }