結果

問題 No.130 XOR Minimax
ユーザー assy1028assy1028
提出日時 2016-12-23 16:16:47
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,886 bytes
コンパイル時間 1,051 ms
コンパイル使用メモリ 100,228 KB
実行使用メモリ 15,780 KB
最終ジャッジ日時 2023-08-21 07:34:27
合計ジャッジ時間 4,712 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 8 ms
4,512 KB
testcase_05 AC 36 ms
15,780 KB
testcase_06 WA -
testcase_07 AC 26 ms
9,640 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int a[100010];

int calc(vector<int>& v, int b) {
    if (b < 0) return 0;
    int l = v.size();
    vector<int> p[2];
    for (int i = 0; i < l; i++) {
        if ((a[v[i]]>>b)&1) p[1].push_back(v[i]);
        else p[0].push_back(v[i]);
    }
    if (p[0].size() == 0) return calc(p[1], b-1);
    if (p[1].size() == 0) return calc(p[0], b-1);
    return (1<<b) + min(calc(p[0], b-1), calc(p[0], b-1));
}

int solve() {
    vector<int> v(n);
    int b = 0;
    for (int i = 0; i < n; i++) {
        v[i] = i;
        int k = 0;
        while ((a[i]>>k) > 0) k++;
        b = max(b, k-1);
    }

    return calc(v, b);
}

void input() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}
0