結果
問題 | No.130 XOR Minimax |
ユーザー |
![]() |
提出日時 | 2020-05-18 18:29:37 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 70 ms / 5,000 ms |
コード長 | 635 bytes |
コンパイル時間 | 1,833 ms |
コンパイル使用メモリ | 173,948 KB |
実行使用メモリ | 10,044 KB |
最終ジャッジ日時 | 2024-09-12 22:57:20 |
合計ジャッジ時間 | 3,412 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h>using namespace std;int dfs(int x, vector<int>& A) {if (A.size() <= 1)return 0;vector<int> V[2];for (auto& a : A) {V[!!(a & (1 << x))].emplace_back(a);}if (V[0].empty())return dfs(x - 1, V[1]);if (V[1].empty())return dfs(x - 1, V[0]);return (1 << x) + min(dfs(x - 1, V[0]), dfs(x - 1, V[1]));}int main() {int N;cin >> N;vector<int> A(N);for (int i = 0; i < N; i++) {cin >> A[i];}sort(A.begin(), A.end());A.erase(unique(A.begin(), A.end()), A.end());cout << dfs(30, A) << endl;}