結果

問題 No.130 XOR Minimax
ユーザー ふーらくたるふーらくたる
提出日時 2017-11-06 23:22:43
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 645 bytes
コンパイル時間 514 ms
コンパイル使用メモリ 60,920 KB
実行使用メモリ 16,192 KB
最終ジャッジ日時 2024-05-03 06:26:49
合計ジャッジ時間 3,315 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 36 ms
16,060 KB
testcase_05 AC 63 ms
16,192 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
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 <iostream>
#include <vector>
using namespace std;

using uint = unsigned int;

int f(int i, vector<uint>& A) {
    if (i == 31 or A.size() == 0) {
        return 0;
    }
    vector<uint> A1, A2;
    for (uint a : A) {
        if (((a >> i) & 1)) A1.emplace_back(a);
        else A2.emplace_back(a);
    }
    if (A2.empty()) return f(i + 1, A1);
    else if (A1.empty()) return f(i + 1, A2);
    else return min((1 << i) | f(i + 1, A1), (1 << i) | f(i + 1, A2));
}

int main() {
    int N;
    cin >> N;

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

    cout << f(0, a) << endl;

    return 0;
}
0