結果
| 問題 | 
                            No.130 XOR Minimax
                             | 
                    
| コンテスト | |
| ユーザー | 
                             koyumeishi
                         | 
                    
| 提出日時 | 2015-02-11 06:41:07 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 154 ms / 5,000 ms | 
| コード長 | 736 bytes | 
| コンパイル時間 | 837 ms | 
| コンパイル使用メモリ | 78,144 KB | 
| 実行使用メモリ | 30,544 KB | 
| 最終ジャッジ日時 | 2024-09-12 22:34:02 | 
| 合計ジャッジ時間 | 3,113 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 21 | 
ソースコード
#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;
long long rec(vector<long long> &A, long long k){
	if(A.size() == 0) return 0;
	if(k==-1) return 0;
	vector<vector<long long>> B(2);
	for(int i=0; i<A.size(); i++){
		B[(A[i]>>k)&1].push_back(A[i]);
	}
	long long y = rec(B[1], k-1);
	if(B[0].size()==0) return y;
	long long x = rec(B[0], k-1);
	if(B[1].size()==0) return x;
	return min(x,y) + (1LL<<k);
}
int main(){
	long long n;
	cin >> n;
	vector<long long> a(n);
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	long long ans = rec(a, 32);
	cout << ans << endl;
	
	return 0;
}
            
            
            
        
            
koyumeishi