結果

問題 No.130 XOR Minimax
ユーザー ともきともき
提出日時 2015-10-12 09:35:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 90 ms / 5,000 ms
コード長 2,913 bytes
コンパイル時間 1,011 ms
コンパイル使用メモリ 120,428 KB
実行使用メモリ 29,916 KB
最終ジャッジ日時 2023-10-10 00:10:21
合計ジャッジ時間 3,345 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
4,836 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 47 ms
29,684 KB
testcase_05 AC 54 ms
29,916 KB
testcase_06 AC 45 ms
17,608 KB
testcase_07 AC 48 ms
17,120 KB
testcase_08 AC 90 ms
7,164 KB
testcase_09 AC 10 ms
5,340 KB
testcase_10 AC 15 ms
6,488 KB
testcase_11 AC 50 ms
15,308 KB
testcase_12 AC 6 ms
4,464 KB
testcase_13 AC 42 ms
12,852 KB
testcase_14 AC 90 ms
6,844 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 64 ms
5,596 KB
testcase_17 AC 68 ms
5,496 KB
testcase_18 AC 72 ms
5,896 KB
testcase_19 AC 86 ms
6,720 KB
testcase_20 AC 44 ms
4,740 KB
testcase_21 AC 90 ms
6,628 KB
testcase_22 AC 22 ms
4,348 KB
testcase_23 AC 8 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cassert>

#include <unordered_set>
#include <unordered_map>
#include <random>
#include <thread>
#include <chrono>

using namespace std;

#define int long long
#define let const auto
#define var auto

#define all(c) c.begin(), c.end()
#define repeat(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x) 
#endif

typedef complex<double> point;

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    for(auto it = v.begin(); it != v.end(); ++it){
        if(it != v.begin()){
            os << ",";
        }
        os << *it;
    }
    return os << "}";
}
template<typename T>
void isort(std::vector<T>& v, std::function<bool(T,T)> comp=less<T>()){
    sort(v.begin(), v.end(), comp);
}
template<typename T>
std::vector<T> sort(std::vector<T> v, std::function<bool(T,T)> comp=less<T>()){
    isort(v);
    return v;
}
template<typename T1, typename T2>
std::vector<T2> rmap(const std::vector<T1>& v, std::function<T2(T1)> f){
    std::vector<T2> t; t.reserve(v.size());
    for(const auto& i: v) t.push_back(f(i));
    return t;
}
std::vector<std::string> split(std::string str, char delim){
    std::vector<std::string> res;
    size_t current = 0, found;
    while((found = str.find_first_of(delim, current)) != std::string::npos){
        res.push_back(std::string(str, current, found - current));
        current = found + 1;
    }
    res.push_back(std::string(str, current, str.size() - current));
    return res;
}
string join(const std::vector<string>& v, string delim){
    string ret = "";
    for(auto it = v.begin(); it != v.end(); ++it){
        if(it != v.begin()){
            ret += delim;
        }
        ret += *it;
    }
    return ret;
}


int sub(const vector<int>& a, int w){
    assert(a.size() != 0 && "A should not be 0");
    vector<int> l,r;
    for(int i : a){
        if(i & (1 << w)) l.push_back(i);
        else             r.push_back(i);
    }
    if(w == 0) return (l.size() >= 1 && r.size() >= 1) ? 1 : 0;
    if(l.size() == 0) return sub(r, w-1);
    if(r.size() == 0) return sub(l, w-1);
    return (1 << w) | min(sub(l, w-1), sub(r, w-1));
}

int solve(const vector<int>& a){
    return sub(a,31);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n; cin >> n;
    vector<int> a(n);
    for(int& i: a) cin >> i;

    cout << solve(a) << endl;
    return 0;
}
0