結果

問題 No.130 XOR Minimax
ユーザー mayoko_mayoko_
提出日時 2015-01-17 11:33:33
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,049 bytes
コンパイル時間 1,177 ms
コンパイル使用メモリ 75,928 KB
実行使用メモリ 15,452 KB
最終ジャッジ日時 2023-09-04 18:27:55
合計ジャッジ時間 3,210 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 36 ms
15,440 KB
testcase_05 AC 62 ms
15,452 KB
testcase_06 AC 49 ms
9,984 KB
testcase_07 WA -
testcase_08 AC 55 ms
4,876 KB
testcase_09 AC 11 ms
4,376 KB
testcase_10 AC 16 ms
4,696 KB
testcase_11 AC 51 ms
8,732 KB
testcase_12 AC 6 ms
4,376 KB
testcase_13 AC 43 ms
7,696 KB
testcase_14 AC 61 ms
4,604 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 43 ms
4,380 KB
testcase_17 AC 45 ms
4,376 KB
testcase_18 AC 47 ms
4,380 KB
testcase_19 AC 58 ms
4,376 KB
testcase_20 AC 28 ms
4,380 KB
testcase_21 AC 60 ms
4,612 KB
testcase_22 AC 14 ms
4,376 KB
testcase_23 AC 5 ms
4,380 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]);
        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