結果

問題 No.130 XOR Minimax
ユーザー rabimearabimea
提出日時 2023-01-25 23:57:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 142 ms / 5,000 ms
コード長 811 bytes
コンパイル時間 1,998 ms
コンパイル使用メモリ 203,024 KB
実行使用メモリ 28,376 KB
最終ジャッジ日時 2023-09-09 07:53:36
合計ジャッジ時間 5,173 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
4,532 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 39 ms
28,376 KB
testcase_05 AC 45 ms
28,232 KB
testcase_06 AC 47 ms
16,440 KB
testcase_07 AC 50 ms
16,108 KB
testcase_08 AC 142 ms
6,372 KB
testcase_09 AC 12 ms
5,404 KB
testcase_10 AC 17 ms
6,352 KB
testcase_11 AC 51 ms
14,356 KB
testcase_12 AC 7 ms
4,376 KB
testcase_13 AC 43 ms
12,056 KB
testcase_14 AC 133 ms
5,740 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 95 ms
4,996 KB
testcase_17 AC 98 ms
4,896 KB
testcase_18 AC 106 ms
5,128 KB
testcase_19 AC 125 ms
5,424 KB
testcase_20 AC 64 ms
4,384 KB
testcase_21 AC 131 ms
5,844 KB
testcase_22 AC 31 ms
4,380 KB
testcase_23 AC 11 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
using vi = vector <int>;
using ll = long long;
using pii = pair <int, int>;
//~ const ll mod = 998244353;
const ll mod = 1e9 + 7;
ll qpow(ll a, ll b, ll m = mod) { ll r = 1, t = a;
	for(; b; b /= 2) { if(b & 1) r = r * t % m; t = t * t % m; } return r; }

int solve(vi v, int b) {
	if(v.size() == 0 || b == -1) return 0;
	
	vi l, r;
	for(int x : v)
		if((x >> b) & 1) l.pb(x - (1 << b));
		else r.pb(x);
	
	if(l.size() > r.size()) swap(l, r);
	
	if(l.size() == 0) return solve(r, b - 1);
	
	return min(solve(l, b - 1), solve(r, b - 1)) + (1 << b);
}

int main() {
	
	ios :: sync_with_stdio(false);
	
	int n; cin >> n;
	vi v(n);
	for(int i = 0; i < n; i ++)
		cin >> v[i];
	
	cout << solve(v, 30) << '\n';
}
0