結果

問題 No.130 XOR Minimax
ユーザー kyuridenamidakyuridenamida
提出日時 2016-02-20 02:24:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 164 ms / 5,000 ms
コード長 714 bytes
コンパイル時間 3,210 ms
コンパイル使用メモリ 148,144 KB
実行使用メモリ 28,188 KB
最終ジャッジ日時 2023-10-10 00:13:11
合計ジャッジ時間 6,047 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
4,456 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 49 ms
28,048 KB
testcase_05 AC 74 ms
28,188 KB
testcase_06 AC 68 ms
16,180 KB
testcase_07 AC 76 ms
15,908 KB
testcase_08 AC 164 ms
5,916 KB
testcase_09 AC 14 ms
5,416 KB
testcase_10 AC 20 ms
6,280 KB
testcase_11 AC 60 ms
14,188 KB
testcase_12 AC 8 ms
4,388 KB
testcase_13 AC 51 ms
11,868 KB
testcase_14 AC 144 ms
5,616 KB
testcase_15 AC 3 ms
4,352 KB
testcase_16 AC 103 ms
4,620 KB
testcase_17 AC 108 ms
5,024 KB
testcase_18 AC 115 ms
5,032 KB
testcase_19 AC 137 ms
5,464 KB
testcase_20 AC 69 ms
4,376 KB
testcase_21 AC 144 ms
5,468 KB
testcase_22 AC 34 ms
4,348 KB
testcase_23 AC 12 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0 ; (i) < (int)(n) ; (i)++)
#define REP(i,a,b) for(int (i) = a ; (int)(i) <= (int)(b) ; (i)++)
#define all(n) (n).begin(),(n).end()



int dfs(int bit,vector<int> a){
	if( bit == -1 ) return 0;
	if( a.size() == 0 ) return 0;
	

	vector<int> d[2];
	rep(i,a.size()) d[a[i] >> bit & 1].push_back(a[i]&~(1<<bit));
	
	if( d[0].size() && d[1].size() ){
		int one = dfs(bit-1,d[0]);
		int zer = dfs(bit-1,d[1]);
		return min(one,zer) + (1<<bit);
	}else if( d[0].size() == 0 ){
		return dfs(bit-1,d[1]);
	}else{
		return dfs(bit-1,d[0]);
	}
}
int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	cout << dfs(30,a) << endl;
}
0