結果

問題 No.130 XOR Minimax
ユーザー sugim48sugim48
提出日時 2014-12-29 23:36:26
言語 C++11
(gcc 8.5.0)
結果
AC  
実行時間 41 ms / 5,000 ms
コード長 494 bytes
コンパイル時間 379 ms
実行使用メモリ 9,824 KB
最終ジャッジ日時 2023-02-24 14:55:58
合計ジャッジ時間 3,403 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
7,656 KB
testcase_01 AC 1 ms
7,668 KB
testcase_02 AC 1 ms
7,668 KB
testcase_03 AC 1 ms
9,696 KB
testcase_04 AC 16 ms
7,656 KB
testcase_05 AC 35 ms
7,588 KB
testcase_06 AC 27 ms
7,680 KB
testcase_07 AC 34 ms
7,668 KB
testcase_08 AC 41 ms
7,572 KB
testcase_09 AC 5 ms
7,672 KB
testcase_10 AC 9 ms
9,772 KB
testcase_11 AC 27 ms
7,608 KB
testcase_12 AC 4 ms
7,592 KB
testcase_13 AC 22 ms
9,824 KB
testcase_14 AC 40 ms
7,612 KB
testcase_15 AC 2 ms
9,684 KB
testcase_16 AC 28 ms
7,668 KB
testcase_17 AC 30 ms
7,680 KB
testcase_18 AC 33 ms
7,596 KB
testcase_19 AC 39 ms
9,820 KB
testcase_20 AC 18 ms
9,712 KB
testcase_21 AC 40 ms
9,696 KB
testcase_22 AC 10 ms
7,592 KB
testcase_23 AC 4 ms
9,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
using namespace std;

int N;
int a[100000];

// a[l, r) の第 i ビット以下の解
int f(int i, int l, int r) {
	if (i == -1) return 0;
	int j;
	for (j = l; j < r; j++)
		if (a[j] & (1 << i))
			break;
	if (j == l || j == r)
		return f(i - 1, l, r);
	int x = f(i - 1, l, j);
	int y = f(i - 1, j, r);
	return min(x, y) + (1 << i);
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> a[i];
	sort(a, a + N);
	cout << f(29, 0, N) << endl;
}
0