結果

問題 No.130 XOR Minimax
ユーザー cielciel
提出日時 2015-12-22 07:37:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 43 ms / 5,000 ms
コード長 536 bytes
コンパイル時間 451 ms
コンパイル使用メモリ 50,796 KB
実行使用メモリ 9,000 KB
最終ジャッジ日時 2023-10-10 00:10:45
合計ジャッジ時間 2,144 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 10 ms
4,352 KB
testcase_05 AC 17 ms
4,348 KB
testcase_06 AC 41 ms
9,000 KB
testcase_07 AC 43 ms
8,892 KB
testcase_08 AC 35 ms
4,352 KB
testcase_09 AC 8 ms
4,348 KB
testcase_10 AC 12 ms
4,352 KB
testcase_11 AC 35 ms
6,424 KB
testcase_12 AC 5 ms
4,348 KB
testcase_13 AC 29 ms
5,856 KB
testcase_14 AC 43 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 30 ms
4,352 KB
testcase_17 AC 31 ms
4,352 KB
testcase_18 AC 33 ms
4,352 KB
testcase_19 AC 40 ms
4,352 KB
testcase_20 AC 19 ms
4,348 KB
testcase_21 AC 42 ms
4,352 KB
testcase_22 AC 9 ms
4,348 KB
testcase_23 AC 4 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

int dfs(int d,const vector<int> &_v){
	if(_v.size()<2)return 0;
	vector<vector<int> > v(2);
	for(auto &e:_v){
		int x=e&(1<<d);
		v[x>>d].push_back(e^x);
	}
	return v[0].empty()?dfs(d-1,v[1]):v[1].empty()?dfs(d-1,v[0]):(1<<d)+min(dfs(d-1,v[0]),dfs(d-1,v[1]));
}

int main(){
	int N;
	scanf("%d",&N);
	vector<int>v(N);
	for(int i=0;i<N;i++)scanf("%d",&v[i]);
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	printf("%d\n",dfs(29,v));
}
0