結果

問題 No.130 XOR Minimax
ユーザー koyumeishikoyumeishi
提出日時 2015-02-11 06:41:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 155 ms / 5,000 ms
コード長 736 bytes
コンパイル時間 848 ms
コンパイル使用メモリ 77,116 KB
実行使用メモリ 30,596 KB
最終ジャッジ日時 2023-10-10 00:07:33
合計ジャッジ時間 3,413 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
5,132 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 61 ms
30,596 KB
testcase_05 AC 87 ms
30,392 KB
testcase_06 AC 70 ms
18,308 KB
testcase_07 AC 80 ms
18,168 KB
testcase_08 AC 155 ms
8,268 KB
testcase_09 AC 14 ms
5,468 KB
testcase_10 AC 21 ms
6,820 KB
testcase_11 AC 64 ms
16,008 KB
testcase_12 AC 8 ms
4,416 KB
testcase_13 AC 54 ms
13,352 KB
testcase_14 AC 139 ms
7,880 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 99 ms
6,068 KB
testcase_17 AC 102 ms
6,172 KB
testcase_18 AC 111 ms
6,384 KB
testcase_19 AC 132 ms
7,232 KB
testcase_20 AC 66 ms
5,064 KB
testcase_21 AC 138 ms
7,532 KB
testcase_22 AC 33 ms
4,372 KB
testcase_23 AC 11 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0