結果

問題 No.130 XOR Minimax
ユーザー mayoko_mayoko_
提出日時 2015-01-17 11:34:47
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,058 bytes
コンパイル時間 1,307 ms
コンパイル使用メモリ 76,684 KB
実行使用メモリ 15,568 KB
最終ジャッジ日時 2023-09-04 18:28:54
合計ジャッジ時間 2,542 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 36 ms
15,568 KB
testcase_05 AC 62 ms
15,388 KB
testcase_06 AC 50 ms
9,780 KB
testcase_07 WA -
testcase_08 AC 56 ms
4,872 KB
testcase_09 AC 11 ms
4,376 KB
testcase_10 AC 16 ms
4,736 KB
testcase_11 AC 53 ms
8,796 KB
testcase_12 AC 6 ms
4,376 KB
testcase_13 AC 44 ms
7,660 KB
testcase_14 AC 63 ms
4,664 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 44 ms
4,376 KB
testcase_17 AC 46 ms
4,376 KB
testcase_18 AC 49 ms
4,380 KB
testcase_19 AC 58 ms
4,396 KB
testcase_20 AC 29 ms
4,376 KB
testcase_21 AC 62 ms
4,656 KB
testcase_22 AC 13 ms
4,380 KB
testcase_23 AC 4 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>

#define INF 1000000000

using namespace std;
typedef long long ll;

const int MAXN = 100010;

int dfs(int bit, vector<int>& v) {
    if (bit == 0) {
        int ret = 0;
        for (int i = 0; i < (int)v.size(); i++) {
            ret ^= v[i];
        }
        return ret;
    }
    if (v.size() <= 1) return 0;
    vector<int> bit0, bit1;
    for (int i = 0; i < (int)v.size(); i++) {
        if (v[i] >> bit & 1) bit1.push_back(v[i]^(1<<bit));
        else bit0.push_back(v[i]);
    }
    if (bit0.empty()) return dfs(bit-1, bit1);
    if (bit1.empty()) return dfs(bit-1, bit0);
    return (1<<bit) + min(dfs(bit-1, bit0), dfs(bit-1, bit1));
}

int main(void) {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    cout << dfs(30, a) << endl;
    return 0;
}
0