結果

問題 No.130 XOR Minimax
ユーザー KKT89KKT89
提出日時 2020-01-11 12:29:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 93 ms / 5,000 ms
コード長 1,045 bytes
コンパイル時間 879 ms
コンパイル使用メモリ 98,660 KB
実行使用メモリ 121,176 KB
最終ジャッジ日時 2023-10-10 00:25:57
合計ジャッジ時間 3,496 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
120,608 KB
testcase_01 AC 32 ms
120,608 KB
testcase_02 AC 33 ms
120,816 KB
testcase_03 AC 33 ms
120,600 KB
testcase_04 AC 46 ms
120,992 KB
testcase_05 AC 52 ms
120,872 KB
testcase_06 AC 50 ms
120,880 KB
testcase_07 AC 54 ms
121,000 KB
testcase_08 AC 66 ms
121,004 KB
testcase_09 AC 37 ms
120,672 KB
testcase_10 AC 38 ms
120,820 KB
testcase_11 AC 55 ms
121,096 KB
testcase_12 AC 34 ms
120,664 KB
testcase_13 AC 50 ms
120,672 KB
testcase_14 AC 92 ms
120,920 KB
testcase_15 AC 33 ms
120,572 KB
testcase_16 AC 72 ms
120,608 KB
testcase_17 AC 74 ms
120,660 KB
testcase_18 AC 78 ms
120,660 KB
testcase_19 AC 89 ms
121,008 KB
testcase_20 AC 56 ms
120,616 KB
testcase_21 AC 93 ms
121,176 KB
testcase_22 AC 44 ms
120,564 KB
testcase_23 AC 36 ms
120,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;
typedef long long int ll;
 
int ans=(1<<30);
 
template<int MX,int MXBIT>struct Trie{
	int nex[MX][2],sz[MX],num=0; // num is last node in trie
	Trie(){
		for(int i=0;i<MX;i++){
			nex[i][0]=nex[i][1]=0;
			sz[i]=0;
		}
	}
	void ins(ll x,int a=1){ // insert or delete
		int cur=0; sz[cur]+=a;
		for(int i=MXBIT-1;i>=0;i--){
			int t=(x>>i)&1;
			if(!nex[cur][t]){
				num++;
				nex[cur][t]=num;
			}
			sz[cur=nex[cur][t]]+=a;
		}
	}
	void dfs(int a,int b,int res=0){
		if(b==-1){
			ans=min(ans,res);
			return;
		}
		if(nex[a][0]&&nex[a][1]){
			for(int i=0;i<2;i++){
				dfs(nex[a][i],b-1,res^(1<<b));
			}
		}
		else{
			for(int i=0;i<2;i++){
				if(nex[a][i]){
					dfs(nex[a][i],b-1,res);
				}
			}
		}
	}
};
 
Trie<(int)1e7,30> T;
 
int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<ll> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
		T.ins(a[i]);
	}
	T.dfs(0,29);
	cout << ans << endl;
}
0