結果

問題 No.130 XOR Minimax
ユーザー krotonkroton
提出日時 2014-12-30 01:09:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 49 ms / 5,000 ms
コード長 530 bytes
コンパイル時間 1,327 ms
コンパイル使用メモリ 144,200 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-10 00:05:46
合計ジャッジ時間 3,155 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int a[100010];
int solve(int L, int R, int shift, int acc){
	if(shift < 0){
		return acc;
	}

	int p = L;
	for(int i=L;i<R;i++){
		if((a[i] >> shift) & 1){
			swap(a[p], a[i]);
			++p;
 		}
	}

	if(p == L || p == R){
		return solve(L, R, shift - 1, acc << 1);
	}

	return min(
		solve(L, p, shift - 1, (acc << 1) | 1),
		solve(p, R, shift - 1, (acc << 1) | 1)
	);
}

int main(){
	int N;
	cin >> N;
	for(int i=0;i<N;i++)cin >> a[i];
	
	cout << solve(0, N, 31, 0) << endl;
	return 0;
}
0