結果

問題 No.130 XOR Minimax
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-04-24 16:33:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 86 ms / 5,000 ms
コード長 880 bytes
コンパイル時間 1,486 ms
コンパイル使用メモリ 168,344 KB
実行使用メモリ 16,040 KB
最終ジャッジ日時 2023-10-10 00:18:00
合計ジャッジ時間 3,468 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 29 ms
16,040 KB
testcase_05 AC 32 ms
15,972 KB
testcase_06 AC 33 ms
9,928 KB
testcase_07 AC 35 ms
9,820 KB
testcase_08 AC 84 ms
4,712 KB
testcase_09 AC 10 ms
4,480 KB
testcase_10 AC 12 ms
4,736 KB
testcase_11 AC 38 ms
9,004 KB
testcase_12 AC 6 ms
4,348 KB
testcase_13 AC 32 ms
7,840 KB
testcase_14 AC 84 ms
4,476 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 64 ms
4,348 KB
testcase_17 AC 65 ms
4,384 KB
testcase_18 AC 65 ms
4,352 KB
testcase_19 AC 78 ms
4,484 KB
testcase_20 AC 39 ms
4,352 KB
testcase_21 AC 86 ms
4,856 KB
testcase_22 AC 20 ms
4,348 KB
testcase_23 AC 7 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)



#define INF INT_MAX/2
int dfs(int bit, vector<int> &v) {
    if (bit < 0) return 0;
    if (v.size() == 0) return 0;

    vector<int> v0, v1;
    for (int x : v) {
        if (x & (1 << bit)) v1.push_back(x & ((1<<bit) - 1));
        else v0.push_back(x & ((1 << bit) - 1));
    }

    if (v0.size() == v.size()) return dfs(bit - 1, v0);
    if (v1.size() == v.size()) return dfs(bit - 1, v1);

    int res = INF;
    res = min(res, dfs(bit - 1, v0));
    res = min(res, dfs(bit - 1, v1));
    res += 1 << bit;

    return res;
}
//-----------------------------------------------------------------------------------
int main() {
    int N; cin >> N;
    vector<int> v;
    rep(i, 0, N) {
        int x;
        scanf("%d", &x);
        v.push_back(x);
    }

    cout << dfs(30, v) << endl;
}
0