結果
| 問題 |
No.698 ペアでチームを作ろう
|
| ユーザー |
Ponzu
|
| 提出日時 | 2023-09-07 20:37:56 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 1,000 ms |
| コード長 | 1,297 bytes |
| コンパイル時間 | 3,437 ms |
| コンパイル使用メモリ | 248,736 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-25 14:21:14 |
| 合計ジャッジ時間 | 4,144 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using T = tuple<int,int,bool>;
using Graph = vector<vector<int>>;
#define pb push_back
#define F first
#define S second
#define rep(i,a) for(int i = 0; i < a; ++i)
#define rrep(i, a, b) for(int i = a; i < b; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define mp(x, y) make_pair(x,y)
template<typename T> bool chmax(T &a,T b){if(a<b){a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b; return true;} return false;}
const int INF = 1<<30;
const ll LINF = 1LL<<60;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<ll> a(n);
rep(i,n) cin >> a[i];
vector<ll> dp(1<<n,0);
dp[0] = 0;
for(int bit = 0; bit < (1<<n); ++bit) {
for(int i = 0; i < n; ++i){
if((1<<i) & bit) continue;
for(int j = i+1; j < n; ++j){
if((1<<j) & bit) continue;
if(i==j) continue;
int index = bit | (1<<i) | (1<<j);
ll power = a[i] ^ a[j];
chmax(dp[index],dp[bit] + power);
}
}
}
cout << dp[(1<<n) - 1] << endl;
}
Ponzu