結果

問題 No.130 XOR Minimax
コンテスト
ユーザー Ysmr_Ry
提出日時 2015-01-19 21:31:19
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 25 ms / 5,000 ms
コード長 763 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 628 ms
コンパイル使用メモリ 67,672 KB
実行使用メモリ 9,928 KB
最終ジャッジ日時 2026-04-04 02:01:33
合計ジャッジ時間 1,473 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// yukicoder 130 (http://yukicoder.me/problems/282)
#include<cstdio>
#include<algorithm>
#include<vector>
#define rep(i,a) for(int i=0;i<(a);++i)
#define all(a) (a).begin(), (a).end()

const int MAX_N = 100000;

int N;
std::vector<int> a;

int f( int d, std::vector<int> &S )
{
	if( S.size() <= 1 )
		return 0;

	std::vector<int> T[2];
	rep( i, S.size() )
		T[S[i]>>d&1].push_back( S[i]^(S[i]&(1<<d)) );

	if( T[0].empty() )
		return f( d-1, T[1] );
	if( T[1].empty() )
		return f( d-1, T[0] );

	return (1<<d)+std::min( f(d-1,T[0]), f(d-1,T[1]) );
}

int main()
{
	scanf( "%d", &N );
	rep( i, N )
	{
		int x;
		scanf( "%d", &x );

		a.push_back(x);
	}

	std::sort( all(a) );
	a.erase( std::unique(all(a)), a.end() );

	printf( "%d\n", f( 29, a ) );

	return 0;
}
0