結果

問題 No.130 XOR Minimax
ユーザー minamiminami
提出日時 2019-03-27 14:24:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 5,000 ms
コード長 1,107 bytes
コンパイル時間 1,702 ms
コンパイル使用メモリ 171,248 KB
実行使用メモリ 9,932 KB
最終ジャッジ日時 2023-10-10 00:24:07
合計ジャッジ時間 3,376 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 9 ms
4,352 KB
testcase_05 AC 15 ms
4,348 KB
testcase_06 AC 39 ms
9,932 KB
testcase_07 AC 41 ms
9,768 KB
testcase_08 AC 32 ms
4,912 KB
testcase_09 AC 8 ms
4,436 KB
testcase_10 AC 11 ms
4,532 KB
testcase_11 AC 31 ms
7,164 KB
testcase_12 AC 5 ms
4,352 KB
testcase_13 AC 27 ms
6,540 KB
testcase_14 AC 38 ms
4,376 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 27 ms
4,352 KB
testcase_17 AC 29 ms
4,348 KB
testcase_18 AC 31 ms
4,356 KB
testcase_19 AC 37 ms
4,456 KB
testcase_20 AC 18 ms
4,352 KB
testcase_21 AC 38 ms
4,420 KB
testcase_22 AC 9 ms
4,352 KB
testcase_23 AC 3 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

int f(int k, vector<int> &v) {
	dump(k, v);
	if (v.size() == 1)return 0;
	vector<int> w[2];
	for (auto x : v) {
		w[x >> k & 1].push_back(x);
	}
	if (w[0].size() == 0)
		return f(k - 1, w[1]);
	if (w[1].size() == 0)
		return f(k - 1, w[0]);
	return (1 << k) + min(f(k - 1, w[1]), f(k - 1, w[0]));
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> a(N); rep(i, 0, N) {
		cin >> a[i];
	}
	sort(all(a));
	a.erase(unique(a.begin(), a.end()), a.end());
	cout << f(30, a) << endl;
	return 0;
}
0