結果

問題 No.130 XOR Minimax
ユーザー startcppstartcpp
提出日時 2016-07-06 20:58:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 50 ms / 5,000 ms
コード長 490 bytes
コンパイル時間 534 ms
コンパイル使用メモリ 61,436 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-10-10 00:14:29
合計ジャッジ時間 2,378 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 19 ms
4,352 KB
testcase_05 AC 45 ms
4,348 KB
testcase_06 AC 31 ms
4,352 KB
testcase_07 AC 42 ms
4,348 KB
testcase_08 AC 50 ms
4,352 KB
testcase_09 AC 7 ms
4,352 KB
testcase_10 AC 10 ms
4,352 KB
testcase_11 AC 32 ms
4,352 KB
testcase_12 AC 4 ms
4,352 KB
testcase_13 AC 26 ms
4,352 KB
testcase_14 AC 49 ms
4,348 KB
testcase_15 AC 2 ms
4,356 KB
testcase_16 AC 35 ms
4,348 KB
testcase_17 AC 35 ms
4,376 KB
testcase_18 AC 38 ms
4,348 KB
testcase_19 AC 45 ms
4,348 KB
testcase_20 AC 22 ms
4,348 KB
testcase_21 AC 48 ms
4,352 KB
testcase_22 AC 11 ms
4,356 KB
testcase_23 AC 4 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#define int long long
using namespace std;

int n;
int a[100000];

//[l, r)
int dfs(int l, int r, int ind) {
	if (ind < 0) return 0;
	
	int i;
	for (i = l; i < r; i++) if ((a[i] >> ind) % 2) break;
	if (i == l || i == r) return dfs(l, r, ind - 1);
	return (1LL << ind) + min(dfs(l, i, ind - 1), dfs(i, r, ind - 1));
}

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	cout << dfs(0, n, 35) << endl;
	return 0;
}
0