結果

問題 No.699 ペアでチームを作ろう2
ユーザー xxxasdfghjkxxxasdfghjk
提出日時 2018-08-12 21:26:48
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,003 bytes
コンパイル時間 695 ms
コンパイル使用メモリ 77,884 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-24 16:23:34
合計ジャッジ時間 3,288 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,672 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 75 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<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
int N,m=-1;
vector<int> sets(0);
bool bo[16384];
void solve(int code,int mochi,int d){
  int back=code;
  if(code == 0){
    m = max(m,mochi);
    return;
  }
  else{
    for(int i=d;i<N;i++){
      if((code >> i)&1){
        code = code ^ (1 << i);
        for(int j=i+1;j<N;j++){
          if((code >> j) & 1){
            code = code ^ (1 << j);
            solve(code,mochi^(sets[i]+sets[j]),1);
            code = code ^ (1 << j);
        }
      }
    }
    if(d == 0)
      return;
    code = back;
    }
  }
}

int main()
{
  int A;
  cin >> N;
  REP(i,N){
    cin >> A;
    sets.push_back(A);
  }
  sort(sets.begin(),sets.end());
  
  solve((1 << N)-1,0,0);
  cout << m << endl;
  return 0;
}

0