結果

問題 No.130 XOR Minimax
ユーザー finefine
提出日時 2017-04-28 00:39:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 5,000 ms
コード長 621 bytes
コンパイル時間 2,016 ms
コンパイル使用メモリ 171,736 KB
実行使用メモリ 9,516 KB
最終ジャッジ日時 2023-10-10 00:17:51
合計ジャッジ時間 3,533 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
4,352 KB
testcase_01 AC 2 ms
4,356 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 9 ms
4,348 KB
testcase_05 AC 15 ms
4,352 KB
testcase_06 AC 38 ms
9,516 KB
testcase_07 AC 39 ms
9,272 KB
testcase_08 AC 32 ms
4,372 KB
testcase_09 AC 8 ms
4,348 KB
testcase_10 AC 11 ms
4,576 KB
testcase_11 AC 31 ms
6,940 KB
testcase_12 AC 5 ms
4,352 KB
testcase_13 AC 26 ms
6,248 KB
testcase_14 AC 38 ms
4,352 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 27 ms
4,352 KB
testcase_17 AC 27 ms
4,352 KB
testcase_18 AC 30 ms
4,356 KB
testcase_19 AC 35 ms
4,352 KB
testcase_20 AC 17 ms
4,348 KB
testcase_21 AC 38 ms
4,376 KB
testcase_22 AC 9 ms
4,348 KB
testcase_23 AC 4 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int solve(int d, vector<int>& v) {
	if (v.size() <= 1) return 0;
	vector<int> w[2];
	for (int x : v) {
		w[(x >> d) & 1].push_back(x);
	}
	if (w[0].empty()) return solve(d - 1, w[1]);
	if (w[1].empty()) return solve(d - 1, w[0]);
	int res = (1 << d);
	res += min(solve(d - 1, w[0]), solve(d - 1, w[1]));
	return res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	a.erase(unique(a.begin(), a.end()), a.end());
	cout << solve(29, a) << endl;
	return 0;
}
0