結果
| 問題 | 
                            No.698 ペアでチームを作ろう
                             | 
                    
| ユーザー | 
                             | 
                    
| 提出日時 | 2023-03-15 13:02:39 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 69 ms / 1,000 ms | 
| コード長 | 1,424 bytes | 
| コンパイル時間 | 818 ms | 
| コンパイル使用メモリ | 96,508 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-09-18 08:42:30 | 
| 合計ジャッジ時間 | 2,160 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 12 | 
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/c++allocator.h:33,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/allocator.h:46,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/string:41,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/locale_classes.h:40,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/ios_base.h:41,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ios:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:38,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/iostream:39,
                 from main.cpp:1:
In member function 'void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = int; _Args = {const int&}; _Tp = int]',
    inlined from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = int; _Args = {const int&}; _Tp = int]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/alloc_traits.h:516:17,
    inlined from 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_vector.h:1281:30,
    inlined from 'void dfs(std::vector<int>, std::vector<bool>)' at main.cpp:53:20:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/new_allocator.h:175:11: warning: 'i' may be used uninitialized [-Wmaybe-uninitialized]
  175 |         { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp: In function 'void dfs(std::vector<int>, std::vector<bool>)':
main.cpp:46:13: note: 'i' declared here
   46 |    
            
            ソースコード
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cassert>
#include <cmath>
#include <bitset>
#include <cctype>
using namespace std;
void chmax(long long& a, long long b) {
    a = max(a, b);
}
int n;
int a[16];
int ans = 0;
void dfs(vector<int> v, vector<bool> used) {
    if (v.size() == n) {
        int res = 0;
        for (int i = 0; i < n; i += 2) res += a[v[i]] ^ a[v[i+1]];
        //printf("v : "); for (int i = 0; i < n; i++) printf("%d ", v[i]); printf("\n");
        //printf("res = %d\n", res);
        ans = max(ans, res);
        return;
    }
    if (v.size() % 2 == 1) {
        for (int i = 0; i < n; i++) {
            if (used[i]) continue;
            v.push_back(i);
            used[i] = true;
            dfs(v, used);
            v.pop_back();
            used[i] = false;
        }
    }
    else {
        int i;
        for (int j = 0; j < n; j++) {
            if (!used[j]) {
                i = j;
                break;
            }
        }
        v.push_back(i);
        used[i] = true;
        dfs(v, used);
        v.pop_back();
        used[i] = false;
    }
}
int main() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    
    vector<int> v;
    vector<bool> used(n, false);
    dfs(v, used);
    cout << ans << endl;
}