結果

問題 No.130 XOR Minimax
ユーザー mayoko_mayoko_
提出日時 2015-01-17 12:00:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 101 ms / 5,000 ms
コード長 989 bytes
コンパイル時間 1,173 ms
コンパイル使用メモリ 81,464 KB
実行使用メモリ 14,488 KB
最終ジャッジ日時 2023-10-10 00:06:44
合計ジャッジ時間 3,139 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
5,924 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 15 ms
4,372 KB
testcase_05 AC 41 ms
4,372 KB
testcase_06 AC 81 ms
14,448 KB
testcase_07 AC 92 ms
14,488 KB
testcase_08 AC 82 ms
9,432 KB
testcase_09 AC 14 ms
4,860 KB
testcase_10 AC 20 ms
5,448 KB
testcase_11 AC 72 ms
9,760 KB
testcase_12 AC 7 ms
4,376 KB
testcase_13 AC 58 ms
8,548 KB
testcase_14 AC 99 ms
8,260 KB
testcase_15 AC 2 ms
4,372 KB
testcase_16 AC 64 ms
6,580 KB
testcase_17 AC 67 ms
7,100 KB
testcase_18 AC 74 ms
7,328 KB
testcase_19 AC 91 ms
7,956 KB
testcase_20 AC 39 ms
5,512 KB
testcase_21 AC 101 ms
8,356 KB
testcase_22 AC 17 ms
4,376 KB
testcase_23 AC 5 ms
4,372 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 d, vector<int>& v) {
    if (v.size() <= 1) return 0;
    vector<int> w[2];
    for (int i = 0; i < (int)v.size(); i++) {
        int x = v[i];
        w[(x>>d)&1].push_back(x^(x&(1<<d)));
    }
    if (w[0].empty()) return dfs(d-1, w[1]);
    if (w[1].empty()) return dfs(d-1, w[0]);
    return (1<<d) + min(dfs(d-1, w[0]), dfs(d-1, w[1]));
}

int main() {
    int N;
    cin >> N;
    set<int> s;
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        s.insert(x);
    }
    vector<int> v;
    for (auto it = s.begin(); it != s.end(); it++) {
        v.push_back(*it);
    }
    cout << dfs(30, v) << endl;
}
0