結果

問題 No.130 XOR Minimax
ユーザー polylogKpolylogK
提出日時 2020-04-28 02:31:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 945 bytes
コンパイル時間 2,263 ms
コンパイル使用メモリ 203,480 KB
実行使用メモリ 16,320 KB
最終ジャッジ日時 2024-05-02 08:26:40
合計ジャッジ時間 4,436 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 33 ms
16,192 KB
testcase_05 AC 38 ms
16,320 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int solve(int k, std::vector<int> now) {
	if(k < 0 or now.empty()) return 0;
	
	std::vector<int> X, Y;
	for(const auto& v: now) {
		if(v >> k & 1) X.push_back(v);
		else Y.push_back(v);
	}
	bool xe = X.empty();
	bool ye = Y.empty();
	
	int x = solve(k - 1, std::move(X));
	int y = solve(k - 1, std::move(Y));
	if(xe) return y;
	if(ye) return x;
	if(x < y) return (x + 1 << k);
	return (y + 1 << k);
}

int main() {
	int n; scanf("%d", &n); std::vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	
	printf("%d\n", solve(30, std::move(a)));
	return 0;
}
0