結果
問題 | No.130 XOR Minimax |
ユーザー |
|
提出日時 | 2017-04-28 00:39:36 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 41 ms / 5,000 ms |
コード長 | 621 bytes |
コンパイル時間 | 2,265 ms |
コンパイル使用メモリ | 174,836 KB |
実行使用メモリ | 9,552 KB |
最終ジャッジ日時 | 2024-09-12 22:45:16 |
合計ジャッジ時間 | 3,439 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h> using namespace std; int solve(int d, vector<int>& v) { if (v.size() <= 1) return 0; vector<int> w[2]; for (int x : v) { w[(x >> d) & 1].push_back(x); } if (w[0].empty()) return solve(d - 1, w[1]); if (w[1].empty()) return solve(d - 1, w[0]); int res = (1 << d); res += min(solve(d - 1, w[0]), solve(d - 1, w[1])); return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); 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 << solve(29, a) << endl; return 0; }