結果

問題 No.130 XOR Minimax
ユーザー Ysmr_RyYsmr_Ry
提出日時 2015-01-19 21:31:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 41 ms / 5,000 ms
コード長 763 bytes
コンパイル時間 557 ms
コンパイル使用メモリ 50,052 KB
実行使用メモリ 8,932 KB
最終ジャッジ日時 2023-10-10 00:07:05
合計ジャッジ時間 2,310 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
4,368 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 1 ms
4,368 KB
testcase_04 AC 11 ms
4,368 KB
testcase_05 AC 17 ms
4,372 KB
testcase_06 AC 39 ms
8,932 KB
testcase_07 AC 41 ms
8,824 KB
testcase_08 AC 33 ms
4,368 KB
testcase_09 AC 8 ms
4,372 KB
testcase_10 AC 11 ms
4,372 KB
testcase_11 AC 32 ms
6,592 KB
testcase_12 AC 5 ms
4,372 KB
testcase_13 AC 26 ms
5,956 KB
testcase_14 AC 38 ms
4,372 KB
testcase_15 AC 2 ms
4,372 KB
testcase_16 AC 27 ms
4,372 KB
testcase_17 AC 29 ms
4,376 KB
testcase_18 AC 30 ms
4,372 KB
testcase_19 AC 37 ms
4,372 KB
testcase_20 AC 18 ms
4,368 KB
testcase_21 AC 39 ms
4,372 KB
testcase_22 AC 9 ms
4,372 KB
testcase_23 AC 4 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 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