結果

問題 No.130 XOR Minimax
ユーザー assy1028assy1028
提出日時 2016-12-23 16:26:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 45 ms / 5,000 ms
コード長 1,912 bytes
コンパイル時間 1,587 ms
コンパイル使用メモリ 100,936 KB
実行使用メモリ 15,856 KB
最終ジャッジ日時 2023-10-10 00:16:20
合計ジャッジ時間 3,333 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,356 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 9 ms
4,520 KB
testcase_05 AC 37 ms
15,856 KB
testcase_06 AC 27 ms
4,812 KB
testcase_07 AC 40 ms
9,712 KB
testcase_08 AC 32 ms
4,736 KB
testcase_09 AC 9 ms
4,348 KB
testcase_10 AC 12 ms
4,352 KB
testcase_11 AC 36 ms
4,532 KB
testcase_12 AC 5 ms
4,352 KB
testcase_13 AC 30 ms
4,472 KB
testcase_14 AC 45 ms
4,552 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 32 ms
4,348 KB
testcase_17 AC 33 ms
4,396 KB
testcase_18 AC 35 ms
4,484 KB
testcase_19 AC 42 ms
4,372 KB
testcase_20 AC 20 ms
4,352 KB
testcase_21 AC 44 ms
4,572 KB
testcase_22 AC 11 ms
4,348 KB
testcase_23 AC 3 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

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();
    if (l <= 1) return 0;
    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[1], 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