結果

問題 No.130 XOR Minimax
ユーザー maine_honzukimaine_honzuki
提出日時 2020-05-18 18:28:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 635 bytes
コンパイル時間 1,516 ms
コンパイル使用メモリ 170,584 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 21:31:14
合計ジャッジ時間 3,601 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 16 ms
6,940 KB
testcase_05 AC 42 ms
6,940 KB
testcase_06 AC 43 ms
6,940 KB
testcase_07 AC 55 ms
6,944 KB
testcase_08 WA -
testcase_09 AC 9 ms
6,940 KB
testcase_10 AC 13 ms
6,940 KB
testcase_11 AC 38 ms
6,940 KB
testcase_12 AC 5 ms
6,940 KB
testcase_13 AC 31 ms
6,944 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int dfs(int x, vector<int>& A) {
    if (A.size() <= 1)
        return 0;

    vector<int> V[2];
    for (auto& a : A) {
        V[!!(a & (1 << x))].emplace_back(a);
    }


    if (V[0].empty())
        return dfs(x - 1, V[1]);
    if (V[1].empty())
        return dfs(x - 1, V[0]);

    return (1 << x) + min(dfs(x - 1, V[0]), dfs(x - 1, V[1]));
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());

    cout << dfs(20, A) << endl;
}
0