結果

問題 No.130 XOR Minimax
ユーザー sugim48sugim48
提出日時 2014-12-29 23:36:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 49 ms / 5,000 ms
コード長 494 bytes
コンパイル時間 1,391 ms
コンパイル使用メモリ 62,044 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-10 00:05:42
合計ジャッジ時間 4,119 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
4,352 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,356 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 19 ms
4,352 KB
testcase_05 AC 43 ms
4,348 KB
testcase_06 AC 31 ms
4,356 KB
testcase_07 AC 41 ms
4,352 KB
testcase_08 AC 49 ms
4,380 KB
testcase_09 AC 7 ms
4,356 KB
testcase_10 AC 10 ms
4,352 KB
testcase_11 AC 32 ms
4,348 KB
testcase_12 AC 4 ms
4,352 KB
testcase_13 AC 26 ms
4,348 KB
testcase_14 AC 48 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 34 ms
4,348 KB
testcase_17 AC 35 ms
4,352 KB
testcase_18 AC 37 ms
4,348 KB
testcase_19 AC 44 ms
4,352 KB
testcase_20 AC 23 ms
4,352 KB
testcase_21 AC 47 ms
4,352 KB
testcase_22 AC 11 ms
4,352 KB
testcase_23 AC 4 ms
4,372 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